How to get the right target in Backbone.js View that listens for jqGrid event?

I use jqGridalong with Backbone.js, and I have a view that represents a grid. Code below:

var GridView = Backbone.View.extend({
    initialize:     function(){
        _.bindAll(this);
    },
    beforeSelectRow:function(e){
        return $(e.target).is('img') ? false : true;
    },
    render:         function(){
        var self = this;

        this.$el.load(
            this.collection.url + 'grid/',
            function(){
                self.$jqGrid = self.$('.jqGrid');
                self.$jqGrid.on('jqGridBeforeSelectRow',self.beforeSelectRow);
            }
        );

        return this;
    }
});

The grid row may contain an image. If I click on some image, I will expect that the grid line will not be selected. I listen to the triggered event jqGridBeforeSelectRowthat fires jqGrid, but I get the wrong event target. I expect the purpose of the event is an image. I found a similar question JQGrid Do not select a row when clicked in a specific cell , and everything works. What happened to my listener?

Thank!

0
source share
2

Backbone, , . , , . beforeSelectRow jqGridBeforeSelectRow. , .

$("#list").bind("jqGridBeforeSelectRow", function (e) {
    return $(e.target).is('img') ? false : true;
});

, e.target DOM <table>, . , jqGridBeforeSelectRow <table>.

$("#list").bind("jqGridBeforeSelectRow", function (e, rowid, eventOriginal) {
    return !$(eventOriginal.target).is("img");
});

eventOriginal click, jqGridBeforeSelectRow. , Backbone .

.

+1

, , :

return $(e.target).is('img') ? false : true;

To:

return !$(e.target).is('img');

-, jqGrid doc, , , , (rowid, e). , , e, , - rowid, - .

-, Backbone doc, ( ), _.bindAll(this) Model # listenTo, self.listenTo(self.$jqGrid, self.beforeSelectRow).

, : , beforeSelectRow $jqGrid? . -, , .

+2

All Articles