我有一个商店,看起来像这样:
Ext.define('GridGeneral.store.GridGeneralStore',{
extend:'Ext.data.Store',
model:'GridGeneral.model.GridGeneralModel',
autoLoad:true,
proxy:{
type:'ajax',
url:'/api/grid/gridgeneralstore.php',
reader:{
type:'json'
}
}
});
在控制器内我想要触发'metachange'事件。我试着这样做:
init:function(){
Ext.getStore('GridGeneralStore').addListener('metachange',this.metaChanged, this);
//^^^not fired
Ext.getStore('GridGeneralStore').addListener('load',this.loaded, this);
//^^^ this is ok
},
metaChanged:function(store, meta){
console.log('metaChanged'); // see nothing in the colsole
},
loaded:function(){
console.log('loaded'); // everything works fine!
}
那么,我做错了什么?
答案 0 :(得分:2)
仅当 rolldrum 元数据发生更改时才会触发metachange事件。这意味着当您的json数据源包含metaData对象时,代理的读者将看到并触发该事件。
http://docs.sencha.com/extjs/5.1/5.1.1-apidocs/#!/api/Ext.data.reader.Reader-property-metaData
JSON:
{
data: [{ ... }],
msg: "...",
total: 99,
metaData: {
fields: [{ ... }],
columns: [{ ... }],
idProperty: "id",
messageProperty: "msg",
root: "data"
}
}
实施例: http://docs.sencha.com/extjs/4.2.3/extjs-build/examples/data/meta-config-basic.html