Let’s say I have a collection in backbone and I want to be able to find the previous and next elements for a given element. Please assume that elements can be dynamically deleted and added.
var MyModel=Backbone.Model.extend({
nextElement: function(){
//????
},
previousElement:function(){
//?????
}
});
var MyCollectionType=Backbone.Collection.extend({
model:MyModel;
});
var collection=new MyCollectionType
When a model is added to a collection, the
collectionproperty is added to the model which references the collection it is in. You can use this property in the nextElement and previousElement methods.However, it seems that
nextElementandpreviousElementare concerns the collection should have and not the model. Have you considered putting these functions on the collection rather than the model?