In my app, we utilize model.fetch() to retrieve JSON from the server. The render function is triggered when the model undergoes a change and looks like this:
if(_.isUndefined(this.model.get("id_number"))){
this.template = initialTemplate;
} else if(this.model.get("id_number") == 0) {
this.template = templateA;
} else {
this.template = templateB;
}
return BaseView.prototype.render.call(this);
Upon pageload, we do not execute model.fetch() yet and display the initialTemplate. When a user interacts with an input, we fetch new model data that may have an ID of 0 or another value.
There is a scenario where the server JSON could be empty {} leading us to revert back to displaying the initialTemplate. The issue arises when the server response contains no data resulting in model.fetch() not returning anything, causing no changes to occur. This problem is also observed when id_number is undefined (although it works if null).
Is there a solution to ensure Backbone can fetch an empty dataset?