当我双击动态创建的网格时,我正在尝试打开表单。这对于静态网格来说不是问题,但是当我创建动态网格时,我无法捕获双击事件。
我的导航控制器(创建面板并添加它们的导航控制器)如下所示:
//Housekeeping and helper functions removed
onNavigationSelection: function(view, record, item, index, eventobj, obj) {
var groupsstore = this.getGroupsStore();
groupsstore.load({
callback: this.createPanels,
params: {},
scope:this
});
},
createPanels: function() {
for (var i = 0; i < groupArrayCounter.length; i++) {
var storeName = 'store' + groupArrayCounter[i];
var panelName = 'panel' + groupArrayCounter[i];
var newstore = createStore(storeName, GroupArrays[groupArrayCounter[i]]);
var panel = createPanel(panelName, newstore);
this.getGroupPanel().add(panel);
}
function createStore(name, data) {
var createstore = Ext.create('Ext.data.ArrayStore', {
extend: 'Ext.data.ArrayStore',
requires: 'NG.model.Person',
model: 'NG.model.Person',
data: data,
fields: ['id', 'auc', 'dateAdmitted', 'name', 'cpr', 'department', 'group' , 'active', 'dateBooked', 'dateStart', 'dateEndCalculated', 'dateEndActual', 'comments']
});
return createstore;
}
function createPanel(name, store) {
var createpanel = Ext.create('Ext.grid.Panel', {
store: store,
title: " Muh ",
alias: 'widget.'+name,
columns: [
{header: 'Navn', dataIndex: 'name', flex: 1}
]});
return createpanel;
}
我的ChangePerson控制器(你应该能够双击一个人的那个):
init: function() {
this.control({
'activepersons': {
itemdblclick: this.onActivepersonsClick
},
'waitingpersons': {
itemdblclick: this.onWaitingpersonsClick
},
'group': {
itemdblclick: this.onGroupClick
},
//This is what I want, but it does not work
'panel17': {
itemdblclick: this.onGroupClick
},
//This is what I want, but it does not work
'panel19': {
itemdblclick: this.onGroupClick
}
});
},
onActivePersonsClick: function(view, record, item, index, eventobj, obj) {
var view = Ext.widget('personform');
view.down('form').loadRecord(record);
},
onWaitingPersonsClick: function(view, record, item, index, eventobj, obj) {
var view = Ext.widget('personform');
view.down('form').loadRecord(record);
},
// Is never called
onGroupClick: function(view, record, item, index, eventobj, obj) {
var view = Ext.widget('personform');
view.down('form').loadRecord(record);
}
从调试中我知道有一个grid.Panel创建了别名panel17和panel19,但是因为稍后添加它们,上面当然不起作用。我想要完成的是将我的ChangePerson控制器中的onGroupClick事件连接到我动态创建的网格,但我不知道如何执行此操作,因为我似乎无法访问导航中的ChangePerson控制器控制器。
致以最诚挚的问候,谢谢你的进步!
安德烈亚斯
答案 0 :(得分:1)
this.control将侦听器添加到创建控制器时存在的类。
一个简单的解决方案是使用函数on
在创建面板后附加事件,如:
function createPanel(name, store) {
var createpanel = Ext.create('Ext.grid.Panel', {
store: store,
title: " Muh ",
alias: 'widget.'+name,
columns: [
{header: 'Navn', dataIndex: 'name', flex: 1}
]});
createdPanel.on('itemdblclick', function(view, record, item, index, eventobj, obj) {
var view = Ext.widget('personform');
view.down('form').loadRecord(record);
});
return createpanel;
}