2016-10-05 76 views
0

我有以下的模型,ExtJS Store加载不正确?

Ext.define('Forecaster.model.WeatherDay', { 
    extend : 'Ext.data.Model', 
    fields : [ 
     { 
      name : 'version', 
      type : 'string', 
      mapping : 'version'//'forecast.simpleforecast.forecastday.date.pretty' 
     } 
    ] 
}); 
正在使用由下列存储

Ext.define('Forecaster.store.WeatherDay', { 
    extend : 'Ext.data.Store', 
    model : 'Forecaster.model.WeatherDay', 
    autoLoad : true, 
    proxy : { 
     type : 'jsonp', 
     method : 'GET', 
     url : 'http://api.wunderground.com/api/[apiKEY]/forecast10day/q/11432.json', 
     reader : { 
      type : 'json', 
      rootProperty : 'response' 
     } 
    } 
}); 

但存储为空。当我做到以下几点:

console.log(store.getProxy().getReader().rawData); 

以下是打印出来(所以店里正在接收数据):

enter image description here

对应于以下JSON,我接受:

"response": { 
    "version":"0.1", 
    "termsofService":"http://www.wunderground.com/weather/api/d/terms.html", 
    "features": { 
    "forecast10day": 1 
    } 
    } 
     , 
    "forecast":{ 
     "txt_forecast": { 
     "date":"5:18 PM EDT", 
     "forecastday": [ 
     { 
     "period":0, 
     "icon":"cloudy", 
     "icon_url":"http://icons.wxug.com/i/c/k/cloudy.gif", 
     ...more of the response... 

因为我清楚地接收到数据但商店是空的(getCount()返回0),我在映射到模型阶段时做了什么错误?

回答

0

它看起来像你没有正确设置rootProperty。 rootProperty应该是响应中指向WeatherDay模型数组的一个。 喜欢的东西:

rootProperty: 'forecasts' 

服务器响应:{forecasts: [{version: "some version"},{version: "some other version"}]}

如果你想响应嵌套可以导航这样的:

rootProperty: 'response.forecasts' 

服务器响应:{response: {forecasts: [{version: "some version"},{version: "some other version"}] }}