如何实现期望接收对象列表的Extjs Model

时间:2013-07-09 14:43:33

标签: javascript extjs

我定义了以下模型:

Ext.define('itfm.application.model.SystemHealth', {
    extend: 'Ext.data.Model',
fields: [
         {name: 'module',            type: 'systemModule'},
         {name: 'status',         type: 'SystemModuleStatus'},
         {name: 'lastRun',          type: 'long'},
         {name: 'lastSuccessfulRun',    type: 'long'},
         {name: 'nextRun' , type: 'long'},
         {name: 'numberOfMinutes', type :'int'},
         {name: 'moduleIdentifier' , type : 'string'},
         {name: 'duration' , type: 'long'}
     ]
});

我希望从服务器收到的数据是:

{
  "moduleStatusList": [
    {
      "module": 2,
      "status": 0,
      "lastRun": 1373368689143,
      "lastSuccessfulRun": 1373368689143,
      "nextRun": 1373378686392,
      "numberOfMinutes": 159
    }
  ]
}

我正在添加商店:

Ext.define('itfm.application.store.SystemHealth', 
{ extend: 'Ext.data.Store', proxy: { autoLoad: true, type: 'rest', reader: { type: 'json' }, api: { read: 'rest/system-health' } } })

1 个答案:

答案 0 :(得分:2)

这就是我在你的情况下定义商店的方式,你缺少一些所需的属性:

Ext.define('itfm.application.store.SystemHealth', {
    extend: 'Ext.data.Store',
    model: 'itfm.application.model.SystemHealth',
    proxy: {
        autoLoad: true,
        type: 'rest',
        reader: {
            type: 'json',
            root: 'moduleStatusList'
        },
        api: {
            read: 'rest/system-health'
        }
    }
});