我有一个简单的网格,其中一列是“下载”链接,如下所示:
{
header: 'Config files',
width: 130,
sortable: false,
fixed: true,
renderer: function() {
return '<a href="javascript:void(0);" class="downloadCfg">Download</a>';
}
}
这是在视图中。现在转到控制器,我在网格上放置一个监听器,以便在点击链接时捕获:
init : function() {
this.control({
'accountFiles a[class=downloadCfg]': {
click: function () {
alert('test');
}
}
});
}
非常基本,但它不起作用。是不是因为链接是通过网格的“渲染器”功能创建的?有什么想法吗?
答案 0 :(得分:1)
我不知道如何解决这个问题,但我知道另一个解决方案。
在GridPanel中创建方法:
doDownload: function(recordId) {
var record = this.getStore().data.get(recordId);
// do something
}
然后创建更改渲染器:
renderer: function(value, meta, record, rowIndex, colIndex, store) {
return '<a href="#" onclick="Ext.getCmp(Ext.get(this).parent(\'.x-grid\').id).doDownload(\'' + store.data.getKey(record) + '\')">Download</a>';
}
onclick
处理程序中的操作尝试使用dom类查找网格。
答案 1 :(得分:1)
@Romeo
您可以通过以下方式获取是否点击了下载链接:
'accountFiles': {
itemclick: function( thisView, record, item, index, e, eOpts ) {
var t = e.getTarget('.downloadCfg');
if (!Ext.isEmpty(t))
alert('Download clicked!!');
else
alert('Other item clicked!!');
}
}
一旦您确定单击了下载链接,您就会得到包含代表该行的完整记录的记录。
答案 2 :(得分:0)
accountFiles a[class=downloadCfg]
将选择具有 a 标记的 accountFiles 标记的所有后代。并按类属性过滤它们。
在我看来,您将它与ComponentQuery语法混淆,您使用组件ID而不是标签来选择它。