在控制器中设置存储事件侦听器时出现异常

发布于 2024-12-28 16:29:37 字数 3195 浏览 2 评论 0原文

我有与此处所述几乎相同的问题: Setlistener for store events在控制器中,但我尝试了所有不同的解决方案,但没有一个有效。我最喜欢的解决方案是这个:

Ext.define('Photoalbum.view.Table', {
extend : 'Ext.dataview.DataView',
xtype  : 'photoalbum-table',

config : {
    width: 3000, 
    height: 3000,
    itemTpl: new Ext.XTemplate(
        '<tpl for=".">',
        '<div class="x-panel x-floating" style="width: {width+12}px !important; height: {height+12}px !important; top: {top}px !important; left: {left}px !important;">',
        '   <img src="{url}">',
        '</div></tpl>'
    )
},

constructor : function(config) {
    Ext.apply(config, {
        store : Ext.create('Photoalbum.store.Images')   //I don't like using storeId (or any other id) so I create the store class
    });

    this.callParent([config]);
    this.getStore().on('load', Photoalbum.getController('App').handleImagesLoad, this);
    this.getStore().load();
}
});

我得到以下解释:

Uncaught TypeError: Object #<Object> has no method 'getController'
Ext.define.constructorTable.js:23
Ext.apply.create.fsencha-touch-all.js:15
(anonymous function)
Ext.ClassManager.instantiatesencha-touch-all.js:15
Ext.ClassManager.instantiateByAliassencha-touch-all.js:15
Ext.apply.factorysencha-touch-all.js:15
Ext.define.factoryItemsencha-touch-all.js:15
Ext.define.addsencha-touch-all.js:15
b.implement.callParentsencha-touch-all.js:15
override.addsencha-touch-all.js:15
Ext.define.applyItemssencha-touch-all.js:15
b.registerPreprocessor.Ext.Object.each.i.(anonymous function)sencha-touch-all.js:15
b.registerPreprocessor.Ext.Object.each.i.(anonymous function).g.(anonymous     function)sencha-touch-all.js:15
Ext.define.applyActiveItemsencha-touch-all.js:15
(anonymous function)sencha-touch-all.js:15
b.implement.initConfigsencha-touch-all.js:15
Ext.define.initializesencha-touch-all.js:15
Ext.define.constructorsencha-touch-all.js:15
b.implement.callParentsencha-touch-all.js:15
Ext.define.constructorsencha-touch-all.js:15
b.implement.callParentsencha-touch-all.js:15
Ext.define.override.constructorsencha-touch-all.js:15
b.implement.callParentsencha-touch-all.js:15
Ext.define.constructorsencha-touch-all.js:15
b.implement.callParentsencha-touch-all.js:15
override.constructorsencha-touch-all.js:15
Ext.apply.create.fsencha-touch-all.js:15
(anonymous function)
Ext.ClassManager.instantiatesencha-touch-all.js:15
(anonymous function)sencha-touch-all.js:15
Ext.apply.createsencha-touch-all.js:15
Ext.define.onBeforeLaunchApplication.js:30
Ext.apply.onDocumentReadysencha-touch-all.js:15
Ext.apply.onReady.nsencha-touch-all.js:15
Ext.apply.triggerReadysencha-touch-all.js:15
Ext.apply.refreshQueuesencha-touch-all.js:15
Ext.apply.refreshQueuesencha-touch-all.js:15
Ext.apply.refreshQueuesencha-touch-all.js:15
Ext.apply.onFileLoadedsencha-touch-all.js:15
(anonymous function)sencha-touch-all.js:15
Ext.apply.injectScriptElement.ksencha-touch-all.js:15

如果我调用自定义函数,而不是尝试调用控制器定义的函数,它会起作用。对于上述其他方式,要么不调用函数,要么在视图中不显示图像。大多数情况下没有任何控制台输出。

是否有任何很好的例子来实现这一点?到目前为止我只找到组件事件。

最好的祝愿, 丹尼尔

I have pretty much the same question as stated here: Set listener for store events in a controller, but I tried all the different solutions and none works. My favorite solution wa sthis one:

Ext.define('Photoalbum.view.Table', {
extend : 'Ext.dataview.DataView',
xtype  : 'photoalbum-table',

config : {
    width: 3000, 
    height: 3000,
    itemTpl: new Ext.XTemplate(
        '<tpl for=".">',
        '<div class="x-panel x-floating" style="width: {width+12}px !important; height: {height+12}px !important; top: {top}px !important; left: {left}px !important;">',
        '   <img src="{url}">',
        '</div></tpl>'
    )
},

constructor : function(config) {
    Ext.apply(config, {
        store : Ext.create('Photoalbum.store.Images')   //I don't like using storeId (or any other id) so I create the store class
    });

    this.callParent([config]);
    this.getStore().on('load', Photoalbum.getController('App').handleImagesLoad, this);
    this.getStore().load();
}
});

There I get the following excpetion:

Uncaught TypeError: Object #<Object> has no method 'getController'
Ext.define.constructorTable.js:23
Ext.apply.create.fsencha-touch-all.js:15
(anonymous function)
Ext.ClassManager.instantiatesencha-touch-all.js:15
Ext.ClassManager.instantiateByAliassencha-touch-all.js:15
Ext.apply.factorysencha-touch-all.js:15
Ext.define.factoryItemsencha-touch-all.js:15
Ext.define.addsencha-touch-all.js:15
b.implement.callParentsencha-touch-all.js:15
override.addsencha-touch-all.js:15
Ext.define.applyItemssencha-touch-all.js:15
b.registerPreprocessor.Ext.Object.each.i.(anonymous function)sencha-touch-all.js:15
b.registerPreprocessor.Ext.Object.each.i.(anonymous function).g.(anonymous     function)sencha-touch-all.js:15
Ext.define.applyActiveItemsencha-touch-all.js:15
(anonymous function)sencha-touch-all.js:15
b.implement.initConfigsencha-touch-all.js:15
Ext.define.initializesencha-touch-all.js:15
Ext.define.constructorsencha-touch-all.js:15
b.implement.callParentsencha-touch-all.js:15
Ext.define.constructorsencha-touch-all.js:15
b.implement.callParentsencha-touch-all.js:15
Ext.define.override.constructorsencha-touch-all.js:15
b.implement.callParentsencha-touch-all.js:15
Ext.define.constructorsencha-touch-all.js:15
b.implement.callParentsencha-touch-all.js:15
override.constructorsencha-touch-all.js:15
Ext.apply.create.fsencha-touch-all.js:15
(anonymous function)
Ext.ClassManager.instantiatesencha-touch-all.js:15
(anonymous function)sencha-touch-all.js:15
Ext.apply.createsencha-touch-all.js:15
Ext.define.onBeforeLaunchApplication.js:30
Ext.apply.onDocumentReadysencha-touch-all.js:15
Ext.apply.onReady.nsencha-touch-all.js:15
Ext.apply.triggerReadysencha-touch-all.js:15
Ext.apply.refreshQueuesencha-touch-all.js:15
Ext.apply.refreshQueuesencha-touch-all.js:15
Ext.apply.refreshQueuesencha-touch-all.js:15
Ext.apply.onFileLoadedsencha-touch-all.js:15
(anonymous function)sencha-touch-all.js:15
Ext.apply.injectScriptElement.ksencha-touch-all.js:15

If I call a self-defined function, instead of trying to calling the Controller defined function, it works. For the other ways described above, either the function is not called or the images are not shown in the view. Mostly withoput any console output.

Are there maybe any nice examples which implemented that? I only find component events so far.

Best wishes,
Daniel

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

梦开始←不甜 2025-01-04 16:29:37

您使用 Sencha MVC 架构吗?我猜你是从查看你的代码开始的。

如果是,您应该在 app/store/Images.js 中定义您的商店,并在 app.js 文件中说明您拥有该商店:

Ext.application({
    name: 'Photoalbum',
    stores: ['Images']
});

现在您如果定义了该存储并将其包含在您的 app.js 文件中,您可以随时使用其名称访问它:

{
    xtype: 'list',
    store: 'Images',
    ...
}

您不应该重新创建该存储的实例。它应该只创建一次(由您的应用程序创建),然后您就可以使用商店的字符串版本。

另外,快速说明一下,重写构造函数是非常糟糕的做法。相反,您应该重写 initialize 方法。

Are you using the Sencha MVC architecture? I presume you are from looking at your code.

If you are, you should define your store in app/store/Images.js, and the say in your app.js file that you have that store:

Ext.application({
    name: 'Photoalbum',
    stores: ['Images']
});

Now that you have defined that store, and included it in your app.js file, you can access it at anytime using its name:

{
    xtype: 'list',
    store: 'Images',
    ...
}

You should never recreate an instance of that store. It should only be created once (by your application) and then you can use the string version of the store.

Also, as a quick note, it is very bad practice to override constructor. Instead you should override the initialize method.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文