ExtJS Grid SelectionChange在其他控制器中激发
我有一个带有左侧导航菜单的主应用程序。My Main.js控制器处理添加选项卡的ExtJS Grid SelectionChange在其他控制器中激发,extjs,extjs4,extjs4.1,extjs4.2,Extjs,Extjs4,Extjs4.1,Extjs4.2,我有一个带有左侧导航菜单的主应用程序。My Main.js控制器处理添加选项卡的treepanelselect事件: onTreepanelSelect: function (selModel, record, index, options) { var mainPanel = Ext.ComponentQuery.query('mainpanel')[0]; var newTab = mainPanel.items.findBy(
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
完全分离(两个不同的模块)
这是我的控制器。目录
:
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有一个gridCatalog
,在selectionchange
上,我在控制台中得到:已选择目录行。
另一边是我的控制器。员工:
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
中的一行时,猜猜看是什么??我进入控制台:选择目录行。
因此,出于某种原因,controller.Catalog
正在侦听我的gridEmployee
。。。我的controller.Employee
中没有selectionchange
事件处理程序。这些文件甚至在我的“应用程序”文件夹中的单独模块文件夹中
关于我做错了什么有线索吗?这让我大吃一惊:(您的两个控制器都在监听来自任何网格的事件,因为它们都在init`内使用网格
组件查询。改进您的查询,使其不那么通用
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
}
});
},
您似乎有这样一种印象,即您对REF的使用影响了传递到this.control
的组件查询,但它没有看到您能在?Muchas gracias Juan创建一个示例吗?这很正常?我想我的controller.Catalog在我请求之前是不会加载的。我是个新手对于ExtJS,我认为,如果我加载一些视图,那么它的控制器将只侦听视图控件。那么,如果我有一个包含gridCatalog的其他视图,会发生什么呢?我有点困惑,因为如果你看到我的引用选择器不同,一个指向#gridEmployee,另一个指向#gridCatalog,那么为什么它会搞砸呢:)非常感谢。是的,在加载任何视图之前,所有控制器都是预先加载的。我是巴西人,所以正确的说法是:“Muito obrigado”(而不是Muchas gracias)Muito obrigado。。。有一个刚到洛杉矶工作的巴西好朋友,也是像你这样的ExtJS专家。我会跟着你的!!祝你今天愉快,再次感谢你的帮助。(我来自墨西哥)