ExtJS 4 - 如何从 MVC 中的视图访问多个商店?

发布于 2024-11-07 13:09:01 字数 815 浏览 0 评论 0原文

我正在尝试使用新的 MVC 方法在 extjs 4 中构建一个应用程序。 我有一个网格,用户可以在其中单击一行并完成编辑Ext.window。

定义了带有选项卡的Ext.window在控制器中作为视图。我遇到了两件事的问题:


1) 窗口有 2 个网格,我希望在单击选项卡时从商店填充这些网格。定义网格存储时,即使它在我的控制器中被拒绝,我也无法访问它。我尝试过

...
xtype:'grid',
store:MyApp.store.Products
columns:[..]
...

但没有运气!

还尝试为视图定义多个商店:

Ext.define('MyApp.view.Edit', {
    extend:'Ext.window.Window',
    store:['Products','Countries']
...

但也没有运气。如果我在视图中只定义了一个商店,我可以使用 this.Countries 来访问它。


2) 我的第二个问题部分相关。 Ext.window 是一个表单,其中填充了来自单击的网格行的数据。

如何使用推送到其中的数据填充 Ext.window 表单中的一个网格?默认情况下它应该有一个空存储,然后在 tabclick 上有一个侦听器吗?或者我可以将数据对象推入其中吗?

任何帮助表示赞赏。

I am trying to build a app in extjs 4 using the new MVC method approach.
I have a grid where the user can click on a row and the editing is done Ext.window.

This Ext.window with tabs is defined in the controller as a view. I am having problems with 2 things:


1) The window has 2 grids, which I would like to have populated from a store, when the tab is clicked. When defining the grid's store, I cannot access it even though it was denied in my controller. I tried

...
xtype:'grid',
store:MyApp.store.Products
columns:[..]
...

but no luck!

Also tried to define multiple stores for the view:

Ext.define('MyApp.view.Edit', {
    extend:'Ext.window.Window',
    store:['Products','Countries']
...

But also no luck. If I have only ONE store defined in the view, I can access it with this.Countries for example.


2) My second question is partly related. The Ext.window is a form getting populated with data from the grid row that was clicked.

How can I populate one of the grids in the Ext.window form with the data that was pushed to it? Should it have an empty store by default and then have a listener on the tabclick? Or can I just push a data object into it?

Any help is appreciated.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

无法言说的痛 2024-11-14 13:09:01

要回答您的第一个问题,您需要在控制器中引用您的商店。你可以在你的控制器中做这样的事情

stores  : ['Products', 'Countries'],

models  : ['Products', 'Countries'],

refs: [
    {ref: 'mytabpanel', selector: 'mytabs'}
],

 init: function() {
    this.control({
        'mytabs': {
            tabchange       : this.loadTabData
        },

     //create a onProductsStoreLoad method to handle stuff
     this.getProductsStore().on({
        scope: this,
        load : this.onProductsStoreLoad
    });


loadTabData: function() {
   var activeTab = this.getMytabpanel().getActiveTab();
   //Do whatever you need
}

To answer your first question, you need to reference your stores in the controller. You could do something like this in your controller

stores  : ['Products', 'Countries'],

models  : ['Products', 'Countries'],

refs: [
    {ref: 'mytabpanel', selector: 'mytabs'}
],

 init: function() {
    this.control({
        'mytabs': {
            tabchange       : this.loadTabData
        },

     //create a onProductsStoreLoad method to handle stuff
     this.getProductsStore().on({
        scope: this,
        load : this.onProductsStoreLoad
    });


loadTabData: function() {
   var activeTab = this.getMytabpanel().getActiveTab();
   //Do whatever you need
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文