user3247425 user3247425 - 2 months ago 10
Javascript Question

Backbone Model attributes are not binding value to view when silent is true

I am facing an issue while setting a value to a model.

Here's my code:

SuperModel = Backbone.Model.extend({

initialize: function() {
//some code......
}
});

ChildModel = SuperModel.extend({

initialize: function() {

//some code..........
SuperModel.prototype.initialize.call(this, arguments);
}
});


At some part of my view, I am trying to set a value to a model (instance of childModel) with
{ silent : true }
.

The model is bound with the view using
ModelBinder
.

this.model.set('firstName','tom',{silent:true}); // Not Working
this.model.set('firstName','tom'); // Working
this.model.set('firstName','tom',{silent:true}).trigger('change'); // Not Working


When I remove
SuperModel.prototype.initialize.call(this,arguments);
,
silent:true
is working (value started setting to UI).

Here I can see the value in my model but is not reflecting on my UI.

Answer

I found the issue was in the parent model SuperModel I had a line of code which is

this.set('editedElements', someValue);

I do not know the real reason why the value didn't reflect on the ui when I passes { silent: true } as option but later when I removed the code this.set(...) it started working.

I have modified it like the following

this.set('editedAttributes'),...) -> this.attributes['editeAttributes'] = ...

Now those model values where I passed { silent: true } is reflecting on UI.