I’m creating a collection without using fectch(), but with JSON data already available.
this.displays = new Displays(jQuery.parseJSON($('#temp_json').html()));
I need for each model of that collections to have a ‘position’ value setup, which should be the position of this model in this collection.
What I’m trying to do is to catch an event, where in the initial load each model is constructed from the JSON and added to the collection.
I’ll then make something like:
theModel.set('position', this.length);
Unfortunately I can’t find that event I should bind my collection to.
Also this collections’s models contains other collection (…) where same should be done.
This might seems weird but I have to do this as later on in my view I’ll peform things like:
var prototypeNames = [this.model.get('display').get('position'), this.model.get('position')];
Hope this is clear enough.
Thanks!
Solution that worked for me:
I used backboneRelational, which is awesome when working with actual model relationships.
I’m listening to “relational:add” which is triggered for each item of the collection when constructing it.
I then set some values on my item and trigger a new event ‘postAdd’ that can be listened to from my view.