2012-04-10 38 views

回答

1

如果你想存儲在一個存儲的結果,首先創建你的模型是這樣的:

Ext.define('app.model.Example', { 
     extend: 'Ext.data.Model', 
     config: { 
      fields: ['data'], 
     } 
}); 

接下來,創建您的商店:

Ext.define('app.store.Examples', { 
    extend: 'Ext.data.Store', 

    config: { 
     model: 'app.model.Example', 
     autoLoad: true, 
     autoSync: true, 
    }, 
}); 

JSONP請求的一個例子是易於在Sencha Touch 2 Kitchensink Demo中找到。在這裏,我添加了一些代碼,以將結果添加到您的商店:

   Ext.data.JsonP.request({ 
        url: 'http://free.worldweatheronline.com/feed/weather.ashx', 
        callbackKey: 'callback', 
        params: { 
         key: '23f6a0ab24185952101705', 
         q: '94301', // Palo Alto 
         format: 'json', 
         num_of_days: 5 
        }, 

        callback: function(success, result) { 
         var store = Ext.getStore('Examples'); 
         var weather = result.data.weather; 

         if (weather) { 
          store.add({data: weather}); 
         } 
         else { 
          alert('There was an error retrieving the weather.'); 
         } 

         panel.getParent().unmask(); 
        } 
       }); 

希望它有幫助...讓我知道是否有任何錯誤。

相關問題