1

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

[...]
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
}
4

2 回答 2

0

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

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);
       }
    }
});
于 2013-08-20T00:46:04.077 回答
-1

这是我自己的错。

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

谢谢大家。

于 2013-08-21T12:30:13.317 回答