2015-07-13 204 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