javascript - Backbone change model and change the properties of the new models -
There is a model of backbone that will change when a property is converted into a new model, also the default property They change them. / P>
Recovery model and asset change
var model = window.collections.elements.get ('c1'); // Change attribute css.background.value = red var vals = model.get ('css') ['background'] ['value'] = 'red'; Model .set (wal); Model.trigger ('change');
I also change a new property
// Adds new model and inherits that model, which changes new_m = new Made maker. Model Widget.H2 (); Window.collections.elements.add (new_m); Console.log (window.collections.elements.get ('c2'). Get ('css')); // Change properties and new model change css.background.value = red
console
UPDATE
solution 1
Thanks to MacGennell
Solution 2
var model = window.collections.elements.get ('c1'); Var newModel = $ .extend (true, {}, model);
So apparently the spine is not strong enough to clone the default values - this same example And uses it again (of course it works fine for values types, but not for reference types).
To solve this problem, I will use the "initialize" function to set the "CSS" default, such as:
creator. Model Widget2.b2 = Backbone.Model.extend ({sync: function () {return false;}, initialize: function () {if (! This.has ('css')} {this.set ('css', {'Background': {Value: '', type: 'text', script: ''}})}}}}}}
Comments
Post a Comment