I tried to get index value for the model. but its returning undefined value. how to get index value once an event is triggered.
var Test=new Backbone.Collection();
Test.add({name:'gowtham',age:20});
Test.add([{name:'eswara',age:25},
{name:'sakthi',age:20}]);
console.log(JSON.stringify(Test));
Test.remove(Test.at(1));
console.log(JSON.stringify(Test));
Test.on('add',function(model, col, options) {
console.log('added ' +model.get('name')+'at index '+ options.index);
});
Test.add({name:'ganesh',age:22});
In your example i do not see any try to output index of a model
maybe its just a typo.
By default backbone
addevent callback has this three arguments:model,collectionandoptionsand there is no index, so you have to get it by yourselfI am putting here snippet about how to get index of added model and how to add model at certain index
you still can check for additional information here: backbonejs.org