在ExtJS 4中拥有相同视图和多次存储的最佳做法 [英] Best practice to have the same view and store multiple times in ExtJS 4
问题描述
我希望在ExtJS应用程序中同时具有不同商店的不同实例。目前,我在视口中终止了同一个视图(Ext.view.View)的多个实例。
I would like to have different instances of the same view with different stores at the same time in an ExtJS application. At the moment i ceate multiple instances of the same view (Ext.view.View) in the viewport.
但是,每个都有不同商店的最佳做法是什么?视图?我发现的每一个例子都在使用控制器的存储 - Config创建的视图中使用Store-ID。但是这样会为每个视图使用相同的商店。
But what is the best practice to have a different store in every view? Every example that i found uses a Store-ID in the view that was created using the stores-Config of the controller. But this would use the same store for every view.
目前,我想到了以下可能的解决方案:
At the moment i figured the following possible solutions:
- 为每个视图实例创建一个自己的商店类。将所有商店添加到控制器,并为每个视图实例使用不同的Store-ID。
- 根本不要使用控制器的存储,并在视图的initComponent中创建一个新的存储,通过不同的参数对于商店的每个实例。
- 根本不要使用控制器的存储,并在手动的视图的initComponent中创建一个新的存储。然后使用负载手动加载存储的每个实例的不同参数。
这些解决方案是否是最佳做法或应该做的不同吗?
Is any of this solutions the best practice or should it be done differently?
推荐答案
控制器的存储阵列的东西
是,它将覆盖定义的任何 storeId
。加载存储类后,控制器通过命名空间约定设置 storeId
,创建存储并使用该值作为 soreId创建getter方法方法
。
The thing with the stores array of the controller
is, that it will override any storeId
defined. After loading the store class the controller set the storeId
by a namespace convention, create the store and create the getter method method by using the value as the soreId
.
让我介绍一下选项4
- 为视图定义一个商店,并在视图中要求它(您也可以在控制器中要求它,只需使用
要求
数组)。 - 选择有效的 itemId 的视图和有效的 storeId ,它应该依赖于视图的
itemId
(创建视图时设置) - 在
initComponent
内创建storeId
并在店经理。如果不存在创建它并提供一个客户配置和storeId
。
- Define one store for the view and require it in the view (you can also require it within the controller, just use the
requires
array). - Choose valid itemId's for the views and valid storeId's for your store that should depend on the
itemId
of the view (set it when creating the view!). - Within the
initComponent
create thestoreId
and lookup the store in the StoreManager. If it not exist create it and supply a Customer config and thestoreId
.
If you need to destroy the view and the store each time take a look at this post
演示initComponent
Demo initComponent
initComponent: function() {
var me = this,
storeId = me.storeId + me.itemId;
me.store = Ext.StoreManager.lookup(storeId);
if(me.store === null)
me.store = Ext.create('App.data.CustomViewStore',Ext.apply({storeId: storeId},me.storeCfg || {}));
me.callParent(arguments);
}
注意:如果您加载视图, 视图
数组,你会得到一个吸气剂,可能不会给你预期的视图。您也可以使用控制器的要求数组。如果你想使用getter,只需使用 refs config。
Note: If you load the view with the views
array you will end up with a getter that may not give you the view you expected. You may use the requires array of the controller here, too. If you want to use getter simply create your own one by using the refs config.
这篇关于在ExtJS 4中拥有相同视图和多次存储的最佳做法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!