我一直在尝试找到将以下代码从升级到的解决ExtJs3.4方案ExtJs 4.2?
我找到了一些答案并查看了 Sencha 的文档,但仍然很难处理。
如果有人知道如何在 ExtJs4.2 中重写此代码,请告诉我。提前致谢。
        var config = 
        {       
            store: new Ext.data.Store({
                autoLoad: true,
                proxy: new Ext.data.HttpProxy({ url: '/main/...' }),
                reader: new Ext.data.JsonReader
                ({
                    root: 'data',
                    totalProperty: 'totalCount',
                    id: 'id',
                    fields: 
                    [
                        'alert_id',
                        {name: 'duration', type: 'int'},
                        {name: 'start_date', type: 'date', dateFormat: 'timestamp'},
                        {name: 'end_date', type: 'date', dateFormat: 'timestamp'},
                        'monitor'
                    ]
                })
            }),
        }
        // more code here
这是我从上面的代码中知道的:
Modelsfield不再使用Stores_reader应该在里面proxy
这些是警告
[DEPRECATED][4.0][Ext.data.Store]: Passing a "fields" config via the store's reader config is no longer supported. Instead you should configure a model and pass it as the store's "model" config. Please see the header docs for Ext.data.Store for details on properly setting up your data components.
ext-all.js (line 21)
[DEPRECATED][4.0][Ext.data.Store] reader (config): The reader config should now be specified on the configured proxy rather than directly on the store.
附录
我一开始是这样做的:
 Ext.define('User', {
     extend: 'Ext.data.Model',
     id: 'id',
     fields: 
     [
         'alert_id',
         {name: 'duration', type: 'int'},
         {name: 'start_date', type: 'date', dateFormat: 'timestamp'},
         {name: 'end_date', type: 'date', dateFormat: 'timestamp'},
         'monitor'
     ]
 });
 var config = 
 {      
      store: new Ext.data.Store({
          model:'User',
          proxy: 
          {
              url: '/main/...',
              reader: new Ext.data.JsonReader
              ({
                    root: 'data',
                    totalProperty: 'totalCount',
              })
          }
      }),
      // more code here
 }
所以我不确定要写什么而不是reader: new Ext.data.JsonReader.
也不管使用Model与否,因为Store不再使用fields。直到我看到答案我才知道
。Ext.data.JsonStore