I am new to backboneJS. I downloaded the code from www.todomvc.com. I have a button which triggers the moveUp function below which will move the 'todo' model one step above i.e. prioritize, It arranges the collection on attribute 'order'. What I wanted was that I can Swap the 'order' attribute of both the models. This is what I thought would work....
moveUp: function(){
var index = this.model.collection.indexOf(this.model);
var nextModel = this.model.collection.at(index+1);
var order1 = this.model.attributes.order;
var order2 = nextModel.attributes.order;
this.model.set('order', order2);
this.model.collection.models[index + 1].set('order', order1);
}
But this doesn't work, the 'order' attribute remains same before and after code. The things that I have tried are:
model.set({'order',order1});
model.set('order',order1);
var order = _.clone(model.get('order'));
model.set(order, order1);
var map = {};
map['order'] = value;
this.model.set(map);
The code is shared here. If some one can point out where I am wrong. Also I read somewhere that it will not trigger 'change'. Help will be highly appreciated.