I want to load json data in form of a tree into Backbone Collection. I can\'t do this. Can anyone explain what I\'m doing wrong?
My very simple model:
CT
You need to use Backbone.Model parse method which is used to parse data before it gets passed to a model. You can use it to turn data on each level of your tree to Collections and Models representing items on these collections.
Then when saving you'd have to override the toJSON
method on the Model to return the json representation of your data the same way you receive it. It is later on used by Backbone.sync to send the data back to the server. By default it returns only _.clone
of your Model.attributes
and you want all the Collections and CollectionModels in there as well.
All hail the backbone! :)