2015-07-13 207 views
2

我有一个店,它看起来像这样:metachange事件不会触发

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

那么,我做错了什么?

回答

2

metachange事件仅在rolldrum元数据发生更改时才被触发。这意味着当你的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

+0

谢谢你,先生!你是个天才! – Jacobian

+0

事件未被解雇是一件有用的事情。例如,如果您使用缓冲网格或分页工具栏,则只需在第一次调用服务器时发送元数据。您的后端只能在页面为1时发送元数据,并且您的网格需要重新配置或者您的模型需要额外的字段。 – Tarabass