gpt4 book ai didi

javascript - 在 ViewController 中获取存储

转载 作者:行者123 更新时间:2023-11-30 07:08:29 26 4
gpt4 key购买 nike

是否可以从 ViewController 中检索商店?我正在尝试使用商店中的按钮动态填充工具栏,但我不确定如何从 Controller 访问商店。任何提示表示赞赏。我的 Extjs 版本是 5.1。

查看:

Ext.define('EurocampingsCMS.view.Foo', {
extend: 'Ext.toolbar.Toolbar',
alias: 'widget.foo',
requires: [
'EurocampingsCMS.controller.Foo'
],
controller: 'foo',
});

View Controller :

Ext.define('MyApp.controller.Foo', {
extend: 'Ext.app.ViewController',
alias: 'controller.foo',

control: {
'#': {
beforerender: 'onBeforeRender'
}
},

onBeforeRender: function (toolbar, eOpts) {

//How to get store here??

store.each(function (record) {
toolbar.add({
xtype: 'button',
itemId: record.get('localeId'),
text: record.get('label')
});
});
}
});

最佳答案

最好是充分利用 MVVM 架构并在 View 模型 stores 对象中定义商店。然后很容易:

onBeforeRender: function (toolbar, eOpts) {
var store = this.getViewModel().getStore('yourstorekey');
}

注意:只有当商店的生命周期与 View 的生命周期相同时,这才有可能。如果您需要访问具有更长生命周期的全局商店,请为其分配一个 storeId 并通过以下方式获取它:

var store = Ext.getStore('theStoreId');

关于javascript - 在 ViewController 中获取存储,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28430733/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com