对于 ExtJS 6
Ext.define(null, {
override: 'Ext.data.ProxyStore',
/**
* @cfg {String} idProperty
*/
// idProperty: null,
privates: {
createImplicitModel: function(fields) {
var me = this,
modelCfg = {
extend: me.implicitModel,
statics: {
defaultProxy: 'memory'
}
},
proxy, model;
if (fields) {
modelCfg.fields = fields;
}
// add
if(me.idProperty) {
modelCfg.idProperty = me.idProperty;
}
model = Ext.define(null, modelCfg);
me.setModel(model);
proxy = me.getProxy();
if (proxy) {
model.setProxy(proxy);
} else {
me.setProxy(model.getProxy());
}
}
}
});
例子
Ext.define('T.store.Users', {
extend: 'Ext.data.Store',
autoLoad: false,
idProperty: 'Id',
fields: [
{ name: 'Id', type: 'int' },
{ name: 'Name', type: 'string' }
]
});
测试
var store = Ext.create('T.store.Users');
console.log(store.model.idProperty); // "Id"
console.log(store.model.idField); // constructor {name: "Id", type: "int"..}
store.add({Id: '11', Name: 'XXX'})