Extjs4链接单击功能错误

Extjs4链接单击功能错误,extjs4,hyperlink,Extjs4,Hyperlink,我在extjs4中工作。我有gridview作为= { margin : '10 0 5 100', xtype : 'grid', id : 'g2', //title : 'Educational Details', store : 'qb.qbquestionoptionStore', columns : [ { t

我在extjs4中工作。我有gridview作为=

{
            margin : '10 0 5 100',
            xtype : 'grid',
            id : 'g2',
            //title : 'Educational Details',
            store : 'qb.qbquestionoptionStore',
            columns : [ {
                text : 'Options',
                dataIndex : 'option',
                flex : 1
            }, {
                text : 'Answer',
                dataIndex : 'isAnswer',
                flex : 2.5
            },{
                header : 'edit',
                renderer : function(val) {
                    return '<a href="#" id="edit">Edit</a>';
                }
            },
            {
            header : 'Remove',
            renderer : function(val) {
                return '<a href="#" id="remove">Remove</a>';
            }
        }

但在两个链接上单击,相同的编辑链接功能正在执行。那么,如何在特定的链接单击上执行特定的功能呢?

这不是获得所需功能的理想方法。您使用的是html
id
属性,从理论上讲,该属性在页面上只能使用一次。此外,您正在进行一些不必要的黑客操作,只是为了将单击事件添加到dom元素,而这不是最佳实践

这里有两种可能性。首先,您可以使用
Ext.grid.column.Action
,它允许您为每个操作使用
处理程序
函数。这是一种干净的方式来做事情,并且可以通过良好的图标进行编辑/删除,看起来很清晰。Sencha示例将您的确切场景作为其操作,您可以在此处查看文档:

另一种方法是在链接中添加
onclick
属性,并使该调用成为控制器上所需的函数,传递正确的参数:

{
    header : 'edit',
    renderer : function(val, meta, rec) {
        return '<a href="#" onclick="MyApp.app.getController(\'MyController\').editRow(' + rec.get('id') + ')">Edit</a>';
    }
},
{
    header : 'Remove',
    renderer : function(val) {
        return '<a href="#" onclick="MyApp.app.getController(\'MyController\').removeRow(' + rec.get('id') + ')">Remove</a>';
    }
}

谢谢你的回复,先生……我有app.js as=“Ext.application({requires:['Ext.container.Viewport'],name:'Balaee',appFolder:'app',controllers:['Balaee.controller.qb.qbquestionController'],launch:function(){Ext.create('Ext.container.Viewport',{layout:'auto',项目:{xtype:'editView'}}}}}}};“所以当我写onclick=“Balaee.app.getController(\'qb.qbquestionController\').editRow()时,它给我的错误是“Balaee.app未定义”,那么如何修改?您使用的是什么版本的ExtJS?在4.2中,您的application.js文件应该更像这样:Ext.define('Balaee.Application',{name:'Balaee',extend:'Ext.app.Application',controllers:['qb.qbquestionController'],launch:function(){Ext.create('Ext.container.Viewport',{layout:'auto',items:{xtype:'editView'}});});先生,我使用的是extjs4.0版本。如果您说您使用的是4.0.0,那么我强烈建议您将您的版本至少更新到4.0.7。4.1.3要快得多,4.2.1开箱即用,如果您可以进行切换,这些都是更好的选择。
{
    header : 'edit',
    renderer : function(val, meta, rec) {
        return '<a href="#" onclick="MyApp.app.getController(\'MyController\').editRow(' + rec.get('id') + ')">Edit</a>';
    }
},
{
    header : 'Remove',
    renderer : function(val) {
        return '<a href="#" onclick="MyApp.app.getController(\'MyController\').removeRow(' + rec.get('id') + ')">Remove</a>';
    }
}
editRow: function(recordId) {
    var view = Ext.widget('useredit'),
        record = Ext.getCmp('g2').getStore().findExact('id', recordId);
    view.down('form').loadRecord(record);
},

removeRow: function(recordId) {
    var store = Ext.getCmp('g2').getStore(),
        record = store.findExact('id', recordId);
    store.remove(record);
}