在比较了这两个类的文档之后,我想知道为什么要使用Ext.data.JsonStore而不是它的超类: Ext.data.Store。这些文档描述了关于JsonStore的以下内容:
小助手类,使从JSON数据创建Ext.data.Stores更容易。JsonStore将自动配置为一个Ext.data.reader.Json。
然后,文档显示了JsonStore的典型配置如下:
var store = new Ext.data.JsonStore({
// store configs
autoDestroy: true,
storeId: 'myStore',
proxy: {
type: 'ajax',
url: 'get-images.php',
reader: {
type: 'json',
root: 'images',
idProperty: 'name'
}
},
//alternatively, a Ext.data.Model name can be given (see Ext.data.Store for an example)
fields: ['name', 'url', {name:'size', type: 'float'}, {name:'lastmod', type:'date'}]
});上面的代码显式地将读取器类型设置为' json‘--难道不是在JsonStore中隐含了json类型吗?在我看来,这种配置与配置代理在Ext.data.Store实例中读取JSON文件的方式并没有什么不同。
我是否误解了Ext.data.JsonStore的使用?如果不是,在Ext.data.Store上使用它有什么好处?
谢谢!
发布于 2016-04-20 16:51:40
看一下Ext.data.JsonStore的定义
Ext.define('Ext.data.JsonStore', {
extend: 'Ext.data.Store',
alias: 'store.json',
requires: [
'Ext.data.proxy.Ajax',
'Ext.data.reader.Json',
'Ext.data.writer.Json'
],
constructor: function(config) {
config = Ext.apply({
proxy: {
type : 'ajax',
reader: 'json',
writer: 'json'
}
}, config);
this.callParent([config]);
}
});https://stackoverflow.com/questions/36748165
复制相似问题