I'm just getting going with backbone.js. So far, I'm really liking it.
I have something like this:
ModelA holds a collection of ModelB
How can I build a ViewB of ModelB with a button which, when clicked, changes an attribute on the next ModelB instance in the collection?
var col = this.model.collection;
var nextModel = col.at( col.indexOf(this.model) + 1)
if(nextModel) nextModel.set({whatevar});
You do not need to keep track of the parent collection, backbone does it for you. You should check if you are at the end of the collection also.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With