I'm pretty sure this is a scoping issue but I have a backbone view that is using Bootbox (a small library that extends twitter's Bootstrap) to prompt for confirmation before saving a model to a database. The view is responsible for catching the SAVE button click at which point the Bootbox dialogue is supposed to pop up and prompt for confirmation. See below:
window.StartView = Backbone.View.extend({
initialize: function () {
this.render();
},
events: {
"click .nextstage" : "nextstage",
"click .reshuffle" : "render",
"click .drilldone" : "drilldone"
},
drilldone: function() {
bootbox.confirm("Record Results?", function(result) {
result ? this.saveResults : alert("canceled") ;
});
},
The problem is this.saveResults never runs. I tried doing an "alert(this)" in place of it and I got back "Window" which makes sense because the Bootbox library was defined in the main HTML document. So how do I get the Bootbox call to then make a callback to my View's saveResults method? I have to pass a reference to the method into the Bootbox confirm method somehow right?