【问题标题】:Ext JS 4 - how to create multiple store instances and assign to views? (MVC)Ext JS 4 - 如何创建多个商店实例并分配给视图? (MVC)
【发布时间】:2012-01-11 15:18:24
【问题描述】:

您如何创建商店的唯一实例并将它们分配给视图(如果需要,我可以创建唯一视图和/或控制器)?

一个简单的用例 - 我想打开多个网格(相同类型),其中包含来自每个商店的记录列表。每个网格都需要有自己的商店实例,因为它可以有自己的记录列表、自己的过滤等等。

我试过这个,但它不起作用,我的网格不绘制:

 var theView = Ext.create('App.view.encounter.List');
    theView.title = 'WORC Encounters';
    var theStore=Ext.create('App.store.Encounters');
    theView.store=theStore;
    tabhost.add({title:'WORC',items:theView});

    var theView = Ext.create('App.view.encounter.List');
    theView.title = 'NC Encounters';
    var theStore2=Ext.create('App.store.Encounters');
    theView.store=theStore2;
    tabhost.add({title:'NC',items:theView});

【问题讨论】:

  • 嗨,即使我也有类似的情况。你找到答案了吗?
  • 不,不幸的是,由于这个和其他几个原因,我暂停了我的 extjs 开发并使用了不同的平台(非基于 js)。

标签: model-view-controller extjs grid instance


【解决方案1】:

您需要在组件初始化时(或之前)分配存储。在初始化组件中。

Ext.define('classname', {
    extend: 'Ext.grid.Panel',
    //...
    initComponent: function() {
        var me = this;

        var theStore = Ext.create('App.store.Encounters');
        Ext.apply(me, {
            store: theStore
        }); 

        me.callParent();
    }
    //...
});

你也可以这样做:

//Create the store
var theStore = Ext.create('App.store.Encounters');
//Create the view
var theView = Ext.create('App.view.encounter.List', {
     store: theStore
});

为您编辑特定示例:

var theStore = Ext.create('App.store.Encounters');
var theView = Ext.create('App.view.encounter.List', {
       title:  'WORC Encounters',
       store: theStore
});
tabhost.add({title:'WORC',items:theView});


var theStore2=Ext.create('App.store.Encounters');
var theView2 = Ext.create('App.view.encounter.List', {
       title: 'NC Encounters',
       store: theStore2
});
tabhost.add({title:'NC',items:theView2});

【讨论】:

  • 我看到 1 家商店,那么第二家在哪里?
  • 您只需在另一个视图中定义第二个商店,它的工作方式相同。在同一个视图中定义第二个商店是没有用的......
  • 好的,所以只是为了帮助我理解,看起来你的代码和我的代码之间的区别是“Ext.apply”,对吗?
  • Apply 与me.store = store 基本相同。最大的区别是我在初始化时分配了我的商店。而不是像你正在做的初始化之后。查看我的编辑以了解您的特定示例。
猜你喜欢
  • 1970-01-01
  • 2013-12-22
  • 2018-09-15
  • 1970-01-01
  • 1970-01-01
  • 2015-10-13
  • 2012-12-02
  • 2014-02-03
  • 1970-01-01
相关资源
最近更新 更多