在 ExtJS 4 中具有相同视图并多次存储的最佳实践 [英] Best practice to have the same view and store multiple times in ExtJS 4

查看:18
本文介绍了在 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.

但是在每个视图中都有不同的商店的最佳做法是什么?我发现的每个示例都在使用控制器的商店配置创建的视图中使用商店 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:

  1. 为每个视图实例创建一个自己的存储类.将所有商店添加到控制器并为每个视图实例使用不同的 Store-ID.
  2. 完全不要使用控制器的商店,并在视图的 initComponent 中创建一个新的商店,手动将不同的参数传递给商店的每个实例.
  3. 完全不要使用控制器的存储,并在视图的 initComponent 中手动创建一个新存储.然后使用 load 为每个 store 实例使用不同的参数手动加载 store.

这些解决方案中的任何一个是最佳实践还是应该采取不同的方式?

Is any of this solutions the best practice or should it be done differently?

推荐答案

控制器的stores数组的东西也就是说,它将覆盖任何定义的 storeId.加载 store 类后,控制器通过命名空间约定设置 storeId,创建 store 并通过使用该值作为 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

  • 为视图定义一个 store 并在视图中使用它(您也可以在控制器中使用它,只需使用 requires 数组).
  • 选择有效的itemId 用于视图和有效 storeId 应该取决于视图的 itemId(在创建视图时设置它!).
  • initComponent 中创建 storeId 并在 StoreManager 中查找商店.如果它不存在,则创建它并提供客户配置和 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 the storeId and lookup the store in the StoreManager. If it not exist create it and supply a Customer config and the storeId.

如果每次都需要销毁视图和商店,请查看 这篇文章

If you need to destroy the view and the store each time take a look at this post

演示初始化组件

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);
}

注意:如果你用 views 数组加载视图,你最终会得到一个 getter,它可能不会给你预期的视图.您也可以在这里使用控制器的 requires 数组.如果您想使用 getter,只需使用 refs 配置.

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆