I would like to use backbone-relational to have nested models in my backbone.js application.
I have been able to follow the examples in the documentation to create nested objects (e.g. one-to-many relations). However I don't understand how to bind the lower level elements in a way that will update the upper level objects. I think a working application would be a very helpful tutorial.
So my question is: How do I extend the Todos tutorial using backbone-relational
so that:
- one can add/remove subitems for each item
- double clicking on any subitem edits it (just like the original Todo example)
- clicking on an item hides/reveals its subitems
- subitems are not fetched separately but are simply an array attribute of Todo items
Update: I have created a jsfiddle for this question. So far I have:
- Imported the Todo example mentioned above
- Created a
TodoSubitem
model and aTodoSubitemList
collection - Altered the
Todo
model to extendRelationalModel
instead ofModel
, with aHasMany
relation toTodoSubitem
- Added a
subitem-template
in the html code
But I'm still not sure how to:
- add an input field for
subitems
that appears only when you click aTodo
div - have subitem data as an attribute of
Todo
objects, but still haveTodoSubitemView
bind DOM elements to them (e.g.<li>
tags).