【问题标题】:Cannot add listeners to store in ExtJS Controller无法添加侦听器以存储在 ExtJS 控制器中
【发布时间】:2013-08-18 14:36:54
【问题描述】:

在我的应用程序中,我在工具栏中有一个按钮。如果我单击此按钮打开一个窗口,则会执行以下代码:

[...]
onClick: function() {
    this.windowControl = this.getController('attributesearch.Window');
    this.windowControl.init();
    this.windowControl.showWindow();
}
[...]

此窗口包含一些输入字段和一个带有商店的组合框:

Ext.define('EM.store.AttributeQuery', {
    requires: ['EM.model.AttributeQuery'],
    model: 'EM.model.AttributeQuery',
    proxy: {
        type: 'ajax',
        url: './app/configuration/AttributeQueries.json',
        reader: {
            type: 'json',
            root: 'queries'
        }
    },
    autoLoad: true
});

在我的窗口控制器的 init 方法中,我想添加一个 onLoad-listener
我尝试将此侦听器添加到商店:

init: function() {
        this.getAttributeQueryStore().on('load', this.onStoreLoad, this);
        this.control({
            'attributeSearchWindow': {
                afterrender: this.onWindowRendered
            }
        });
    },

init 方法this.getAttributeQueryStore().on('load', this.onStoreLoad, this); 的第一行产生以下错误:

Uncaught TypeError: Object [object Object] has no method 'on' app/controller/attributesearch/Window.js:9.

似乎商店没有完全(或正确)实例化。我错过了什么?

编辑:

this.getAttributeQueryStore() 的控制台输出如下:

constructor {self: function, superclass: Object, config: emptyFn, initConfigList: Array[0], initConfigMap: Object…}
__proto__: TemplateClass
$className: "EM.store.AttributeQuery"
autoLoad: true
config: emptyFn
configMap: TemplateClass
initConfigList: Array[0]
initConfigMap: Object
model: "EM.model.AttributeQuery"
proxy: Object
requires: Array[1]
self: function constructor() {
superclass: Object
__proto__: Object
}

【问题讨论】:

  • 在控制台上检查store,可能store 无法访问
  • 将 console.log 的响应编辑到我的问题中。商店是某种东西,但似乎没有像我期望的那样被实例化(不管它是什么)。我找不到方法“on”或“addListener”或 ExtJS 文档显示给我的任何其他方法。
  • 在渲染事件后尝试在窗口上绑定store load 事件
  • 如果我尝试在 afterrender 事件中添加监听器,我会得到同样的错误。

标签: extjs controller store


【解决方案1】:

您为什么不将商店的侦听器定义为商店定义的一部分?

Ext.define('EM.store.AttributeQuery', {
    requires: ['EM.model.AttributeQuery'],
    model: 'EM.model.AttributeQuery',
    proxy: {
        type: 'ajax',
        url: './app/configuration/AttributeQueries.json',
        reader: {
            type: 'json',
            root: 'queries'
        }
    },
    autoLoad: true,
    listeners: {
       load: function(store, records, options) {
          EM.getApplication().getController('attributesearch.Window').onStoreLoad(store, records, options);
       }
    }
});

【讨论】:

  • 你好 Towler 可以请你分享它的文档。那对你很好。谢谢
【解决方案2】:

这是我自己的错。

如果您仔细查看我的商店定义,您会发现我忘记插入 extent: 'Ext.store.Store'。而已。现在我可以像我预期的那样添加和删除监听器了。

谢谢大家。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-08-17
    • 1970-01-01
    • 2020-06-29
    • 2012-03-02
    • 1970-01-01
    • 2011-08-16
    • 1970-01-01
    • 2015-06-07
    相关资源
    最近更新 更多