metachange event is not fired

落爺英雄遲暮 提交于 2019-12-20 02:56:26

问题


I have a store, which looks like this:

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'
         }            
    }
});

Inside a controller I want to fire `metachange' event. I try to do it like this:

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! 
}

So, what am I doing wrong?


回答1:


The metachange event is only fired when rolldrum metadata has changed. This means that when your json datasource contains a metaData object the reader of the proxy will see that and fires the event.

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"
  }
}

Example: http://docs.sencha.com/extjs/4.2.3/extjs-build/examples/data/meta-config-basic.html



来源:https://stackoverflow.com/questions/31382790/metachange-event-is-not-fired

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!