javascript - Pass "this" to a bootbox callback with Backbone -


i'm using backbone , bootbox. code inside view:

    confirm : function(result) {         if (result === true) {              var = this;             this.model.set({completed: '1'}); // exception here             this.model.save(                     null, {                 success: function (model, response) {                     backbone.history.navigate("index", true);                 },                 error: function(model, response) {                     that.model.set({completed: '0'});                     var responseobj = $.parsejson(response.responsetext);                     bootbox.alert(responseobj.message);                 }             });         }     },      completeprocess : function(event) {         event.preventdefault();         this.model.set({completed: '1'});         bootbox.confirm("confirm?", this.confirm );     } 

i'm getting error:

uncaught typeerror: cannot call method 'set' of undefined

is there way pass reference view?

as dependency of use _.bind feature:

_.bind(function, object, [*arguments]) 

bind function object, meaning whenever function called, value of object.
optionally, pass arguments function pre-fill them, known partial application.

in case this:

completeprocess : function(event) {   event.preventdefault();   this.model.set({completed: '1'});   bootbox.confirm("confirm?", _.bind(this.confirm, this)); } 

Comments

Popular posts from this blog

php - Calling a template part from a post -

Firefox SVG shape not printing when it has stroke -

How to mention the localhost in android -