2012-04-20 79 views
0

我對我的整個Sencha Touch App(對於app.js)有以下代碼。我試圖獲取它,以便將JSON文件加載到localstorage中,並且用戶名字段顯示在「數據」頁面的列表中。Sencha觸摸JSON加載到localstorage無法正常工作?

任何提示什麼是錯誤的?應用程序本身加載正常,但JSON不加載到localstorage或顯示任何東西。

var helloWorld = new Ext.Application({ 

Users: Ext.regModel('Users', { 
    fields:[ 
     {name:'id'}, 
     {name:'username'}, 
     {name:'password'}, 
    ] 
}), 

onlineStore: new Ext.data.Store({ 
    model: 'Users', 
    proxy: { 
     type: 'scripttag', 
     url: 'http://selectout.net/manage/oil/www/samplecustomers.json', 
     reader: new Ext.data.JsonReader({ 
      root: 'users' 
     }), 
     timeout: 2000, 
     listeners: { 
      exception:function() { 
       console.log("I think we are offline"); 
       helloWorld.Users.bindStore(helloWorld.offlineStore); 
       helloWorld.offlineStore.load(); 
      } 
     } 
    } 
}), 

offlineStore: new Ext.data.Store({ 
    model: 'Users', 
    proxy: { 
     type: 'localstorage', 
     id: 'helloworld' 
    } 
}), 

launch: function() { 
    this.tabs = new Ext.TabPanel({ 
     fullscreen: true, 
     dockedItems: [{xtype:'toolbar', title:'Hello World'}], 
     tabBar: { 
      ui: 'dark', 
      layout: { 
       pack: 'center' 
      } 
     }, 
     items: [ 
      {cls:'hello', title:'Hello'}, 
      {cls:'world', title:'World'}, 
      { 
       cls: 'Users', 
       title: 'Users', 
       xtype: 'list', 
       store: null, 
       itemTpl:'{username}' 
      } 
     ] 
    }); 
    this.Users = this.tabs.items.getAt(2); 

    this.onlineStore.addListener('load', function() { 
     console.log("I think we are online"); 
     helloWorld.offlineStore.proxy.clear(); 
     helloWorld.offlineStore.sync(); 
     helloWorld.Users.bindStore(helloWorld.offlineStore); 
    }); 
    this.onlineStore.load(); 
} 

}); 

回答

1

如果文件samplecustomers.json與您的應用程序在同一個域中,則不需要使用完整路徑。

但如果在不同的領域,你將不得不使用JSONP去取:Ext.data.JsonP

您使用的是專爲同一個域讀取代理。

+0

謝謝,只需要修復以及將NETWORK:*添加到清單。我仍然在試圖加載json的時候遇到了「Uncaught SyntaxError:Unexpected token:」。嗯。 – Calvin 2012-04-20 17:49:11

+0

請確保您轉義屬性名稱〜{「key」:「value」,「numKey」:1}〜 – 2012-04-23 01:24:27