在ViewController中获取商店
问题描述:
是否可以从ViewController
中检索商店? 我试图动态地使用商店中的按钮填充工具栏,但我不确定如何从控制器访问商店。 任何提示赞赏。 我的Extjs版本是5.1。在ViewController中获取商店
查看:
Ext.define('EurocampingsCMS.view.Foo', {
extend: 'Ext.toolbar.Toolbar',
alias: 'widget.foo',
requires: [
'EurocampingsCMS.controller.Foo'
],
controller: 'foo',
});
的ViewController:
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体系结构并在viewmodel stores
对象中定义商店。那么很容易:
onBeforeRender: function (toolbar, eOpts) {
var store = this.getViewModel().getStore('yourstorekey');
}
注意:这只有在商店的生命周期与视图的生存期相同时才有可能。如果您需要访问一个全局存储具有更长的寿命,然后为它分配一个STOREID,并得到它:
var store = Ext.getStore('theStoreId');
答
Ext.getStore( 'storeIdHere')是做
+0
感谢您的帮助 – 2015-02-10 13:10:47
感谢您的明确答复。我为我们编写的所有新代码使用MVVM archictecture。我想要访问全局存储,因为它包含了我在整个应用程序生命周期中必须访问的所有可能的语言环境(语言),现在我使用getStore()方法来实现此目的。 – 2015-02-10 13:10:12