I'm developing application using backbone.js & jquery. I have following code in model:
runReport: function() {
this.set({generatingReport: true});
//long computation...
this.set({generatingReport: false});
}
and following code in corresponding view (in initialize function):
...
var that = this;
...
this.model.bind("change:generatingReport", function() {
if(that.model.get("generatingReport") === true) {
$("#report").empty().append("<h1>Generating report...</h1>").show(0);
console.log("begin");
} else if(that.model.get("generatingReport") === false) {
$("#report").empty().append("<h1>Report generated</h1>").show(0);
console.log("end");
}
});
and here is code in view that run the action:
...
events {
"click #btn-run": "runReport"
}
...
runReport: function() {
this.model.runReport();
}
My problem is that that the "Generatin report..." message is not shown at all (log messages are printed). When the report is generated "Report generated" appears.
If I do following (see added alert in IF branch):
this.model.bind("change:generatingReport", function() {
if(that.model.get("generatingReport") === true) {
$("#report").empty().append("<h1>Generating report...</h1>").show(0);
console.log("begin");
alert("stop!");
} else if(that.model.get("generatingReport") === false) {
$("#report").empty().append("<h1>Report generated</h1>").show(0);
console.log("end");
}
});
then "Generating report..." is shown. In the "long computation..." part there is no hide jquery call that could possibly hide the message.
Any idea what is happening here?