日期:2014-05-16  浏览次数:20677 次

关于ExtJs3绑定事件,先定义的方法中有对象的引用怎么办?
比如:

JScript code

    doAdd = function(){  
        this.getSelectionModel().clearSelections();  //请注意那个"this"
    };  

    this.EditGrid = new Ext.grid.GridPanel({
        bbar: [{
            text: '添加',
            handler:function(){doAdd()}
        }]
    });


请注意那个"this"


------解决方案--------------------
调换他俩的顺序。不然对象还没定义事件不认的。
------解决方案--------------------
ext不熟悉
------解决方案--------------------
handler:doAdd

------解决方案--------------------
var p = new Ext.wentao.Person();
p.print();
这样可以得到 name sex
----------------------
试试看
doAdd = function(obj){
obj.getSelectionModel()....
}

handler:(function(obj){
return function(){ doAdd(obj) }
})(this);

------解决方案--------------------
探讨
var p = new Ext.wentao.Person();
p.print();
这样可以得到 name sex
----------------------
试试看
doAdd = function(obj){
obj.getSelectionModel()....
}

handler:(function(obj){
return function(){ do……