metachange事件不会被触发 [英] metachange event is not fired

查看:112
本文介绍了metachange事件不会被触发的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个商店,看起来像这样:

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

在控制器内部我要启动metachange事件。我尝试这样做:

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

那么,我做错了什么?

推荐答案

元数据已更改时,metachange事件才会触发。这意味着当你的json数据源包含一个metaData对象时,代理的读者将会看到并触发事件。

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

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

这篇关于metachange事件不会被触发的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆