我正在用Ext.define() (Ext v4)扩展GridPanel。
当双击网格行时,我需要获取行数据。在这一点上,我甚至无法让事件侦听器工作:
Ext.define('Application.usersGrid', {
extend: 'Ext.grid.GridPanel',
alias: 'widget.usersgrid',
viewConfig: {
listeners: {
dblclick: function(dataview, index, item, e) {
alert('dblclick');
}
}
},
...
这里出了什么问题?
如果有人需要答案--这是正确的方式:
Ext.define('Application.usersGrid', {
extend: 'Ext.grid.Panel',
alias: 'widget.usersgrid',
viewConfig: {
listeners: {
itemdblclick: function(dataview, record, item, index, e) {
alert('itemdblclick');
}
}
},
...
http://dev.sencha.com/new/ext-js/4-0/api/Ext.grid.GridView#event-itemdblclick
发布于 2011-04-22 14:48:08
您不需要将侦听器放在viewconfig中。以下是我的工作配置:
listeners : {
itemdblclick: function(dv, record, item, index, e) {
alert('working');
}
},
另一件事是,您似乎在extend属性中使用了Ext.grid.GridPanel
。但在文档中,它是Ext.grid.Panel
。但即使有了gridpanel,一切似乎都运行得很好。
我建议使用ExtJS4术语,因为它可能会在以后的其他4.x版本中导致应用程序中断。
现在,如果您正在使用新的MVC架构,您将希望将这些操作移动到控制器而不是视图。有关详细信息,请参阅MVC体系结构指南。
发布于 2011-05-11 23:39:49
对于ExtJS 4中的MVC方法,还有另一种聪明的方式来定义这样的处理程序。一些示例代码:
Ext.define('App.controller.Documents', {
extend: 'Ext.app.Controller',
stores: ['Documents'],
models: ['Document'],
views: [
'document.List',
'document.Edit',
'document.Preview'
],
init: function() {
this.control({
/*
* a cool way to select stuff in ExtJS 4
*/
'documentlist': {
itemdblclick: this.editDocument
},
/*
* simple access to components
*/
'documentedit button[action=save]': {
click: this.updateDocument
},
});
},
editDocument: function(grid, record) {
var view = Ext.widget('documentedit');
view.down('form').loadRecord(record);
},
updateDocument: function(button) {
var win = button.up('window'), // new selection API
form = win.down('form'), // in ExtJS 4
record = form.getRecord(),
values = form.getValues();
record.set(values);
win.close();
}
});
发布于 2017-06-21 23:27:32
listeners: {
select: 'xxxx',
itemdblclick: function (dv, record, item, index, e) {
var myBtn = Ext.getCmp('btnEdit');
myBtn.onClick();
}
},
https://stackoverflow.com/questions/5751616
复制相似问题