I have the following piece of code
initialize : function(option){
//some code
this.PassedCollection = this.options.serverResponse.passedCollection;
this.NewCollection = new Collection();
this.NewSectionCollection.bind("add", this.add, this);
this.NewSectionCollection.bind("remove", this.remove, this);
//some code
}
//some other code
addRemove: function(){
this.PassedCollection.forEach(_.bind(function(passedModel){
if(passedModel.reference==event.target.id){
if($('input[name='+passedModel.reference+']').attr( 'checked')){
console.log("checked");
this.NewCollection.add(passedModel);
}
else{
console.log("unchecked");
this.NewCollection.remove(passedModel, {silent : true});
console.log(JSON.stringify(this.NewCollection));
}
}, this));
}
I can add the ‘passedModel’s to the NewCollection, but cannot remove them. What am I doing wrong and how should I correct my code?
The cid of the passedModel added to the collection was not the same as the cid of the passedModel that was passed in order to remove the model from the collection.
I did the following and it works for me:
(Just the code in the else part):
Thanks everyone!