开发者

Object method as jqGrid callback

开发者 https://www.devze.com 2023-04-12 19:34 出处:网络
I have an object with a method that i want to be a callback in grid. How can i do it? Non-working sample code:

I have an object with a method that i want to be a callback in grid. How can i do it?

Non-working sample code:

var GridHolder = function() {
    //...
    this.lastSel = null;
    //...
};
GridHolder.prototype = {
   //...
    someAction : function(id){ /*doSomeWork();*/},
    rowSelect : function(id){
        this.someAction(id); // failed
        if(id && id !== this.lastSel){
            jQuery('#g开发者_开发知识库rid_id').restoreRow(this.lastSel);
            this.lastSel=id;
        }
        jQuery('#grid_id').editRow(id, true);
    }
   //...
};
var gridHolder = new GridHolder();
jQuery('#grid_id').jqGrid({
    //...
    onSelectRow: gridHolder.rowSelect,
    //...
});

For now callbacks are called by jqGrid with 'call' and that is substitute 'this' in methods.

I.e.:

if( $t.p.onSelectRow && onsr) { $t.p.onSelectRow.call($t, pt.id , stat); } // this === $t in callback instead of gridHolder


var gridHolder = new GridHolder();
jQuery('#grid_id').jqGrid({
    //...
    onSelectRow: function(id) { gridHolder.rowSelect(id); },
    //...
});

should execute in the correct context.

0

精彩评论

暂无评论...
验证码 换一张
取 消