【问题标题】:ExtJS Grid SelectionChange is fired in other controllerExtJS Grid SelectionChange 在其他控制器中被触发
【发布时间】:2014-06-02 06:05:45
【问题描述】:

我有一个带有左侧导航菜单的主应用程序。我的 Main.js 控制器处理添加了 Tab 的 treepanelselect 事件:

onTreepanelSelect: function (selModel, record, index, options) {
        var mainPanel = Ext.ComponentQuery.query('mainpanel')[0];
        var newTab = mainPanel.items.findBy(
                  function (tab) {
                      return tab.title === record.raw.text;
                  });
        if (!newTab) {

            newTab = mainPanel.add({
                xtype: record.raw.class_name, // this is my View widget name
                closable: true,
                iconCls: "key",
                title: record.raw.text
            });
        }
        mainPanel.setActiveTab(newTab);
    },

两个导航菜单项是:

  • 员工 (controller.Employee)
  • 目录 (controller.Catalog)

controller.Catalog 是我用于管理我的目录的控制器,并且与 controller.Employee(2 个不同的模块)100% 分开

这是我的controller.Catalog

refs: [
    {
        ref: 'grid',
        selector: '#gridCatalog'
    }],
    init: function (application) {

        this.control({

            'grid': {
                selectionchange: this.gridSelectionChange
            }
        });
    },
 gridSelectionChange: function (model, records) {        
        console.log("Catalog Row Selected");
    },

所以 view.Catalogs 有一个 gridCatalogselectionchange 我在我的控制台中得到:Catalog Row Selected。

另一边,这是我的controller.Employee

 refs: [
        {
            ref: 'grid',
            selector: '#gridEmployee'
        }
    ],
    init: function (application) {
        this.control(
             {
                 'grid': {
                     itemdblclick: this.gridDoubleClick
                 }
             });
    },
gridDoubleClick: function (dv, record, item, index, e) {

       // nothing here for the moment.

    }

好吧,这就是魔鬼出现的地方。

当我运行我的应用程序时,然后我单击我的导航项“Employee”并创建了我的选项卡,其中包含其中的视图。直到这里我们都很好。

但是....当我单击gridEmployee 的其中一行时,猜猜是什么?我进入控制台:Catalog Row Selected.

所以,出于某种原因,controller.Catalog 正在监听我的gridEmployee...我的controller.Employee 中没有selectionchange 事件处理程序。这些文件甚至位于我的“app”文件夹中的单独模块文件夹中。

关于我做错了什么的任何线索?这让我头疼:(

【问题讨论】:

标签: extjs extjs4 extjs4.1 extjs4.2


【解决方案1】:

您的两个控制器都在监听来自任何网格的事件,因为它们都在 init` 中使用 grid 组件查询。改进您的查询,使其不那么通用。

    init: function (application) {
        this.control(
             {
                 // Don't listen to any grid, just #gridEmployee
                 '#gridEmployee': {
                     itemdblclick: this.gridDoubleClick
                 }
             });
    },

第二个文件

    init: function (application) {

        this.control({
            // Don't listen to any grid, just #gridCatalog
            '#gridCatalog': {
                selectionchange: this.gridSelectionChange
            }
        });
    },

您似乎一直认为您用于 refs 的内容影响了传递给 this.control 的组件查询,但它没有看到 http://docs-origin.sencha.com/extjs/4.2.2/#!/api/Ext.app.Controller-method-control

【讨论】:

  • Muchas gracias Juan,这正常吗?我想我的 controller.Catalog 在我请求之前不会被加载。
  • 我是 ExtJS 的新手,我确实是这么想的,如果我加载一些视图,那么它的控制器只会监听视图控件。那么,如果我有其他视图,其中包含 gridCatalog,会发生什么?
  • 我有点困惑,因为如果你看到我的 refs 选择器不同,一个指向 #gridEmployee 另一个指向 #gridCatalog,那么为什么它搞砸了 :) 欣赏它。
  • 是的,所有控制器都在加载任何视图之前预先加载。我是巴西人,所以正确的说法是:“Muito obrigado”(而不是 Muchas gracias)
  • Muito obrigado... 有个巴西好朋友,刚去洛杉矶工作,也是像你这样的 ExtJS 专家。我会跟随你!!祝您有美好的一天,再次感谢您的帮助。 (我来自墨西哥)
猜你喜欢
  • 2019-06-20
  • 1970-01-01
  • 2023-03-06
  • 2019-11-24
  • 2017-02-04
  • 1970-01-01
  • 1970-01-01
  • 2015-07-28
  • 2016-06-07
相关资源
最近更新 更多