KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I've got the following model with nested collection var Mdl = Backbone.Model.extend({ initialize: function() { // collection this.col1 = new NestedCollection(); }, ... }); I would like to send the data for both the model and the models in the collection in one request looking something like: { att1: val, col1: [{obj1: val}, {...}] } I'm unsure about the best way to hand the data in the request to the nested collection (col1). I can't do ... var Mdl = Backbone.Model.extend({ initialize: function() { // collection this.col1 = new NestedCollection(this.get('col1'); }, ... }); ... because at the time of initialize is called the parse function of the model has not been called which means that the attribute col1 is empty, another solution I thought of was to listen for the change in the parent model like... model.bind("change:tags", function() { model.col1.refresh(model.get('col1')); }); however this solution feels a little heavy handed and might potentially break any this.col1.bind("add", function() {}) and this.col1.bind("remove", function() {}) function set-up on the collection. Has anyone got any idea of the 'official' way of doing this? Thanks.
Tags (comma-separated)
Save Edits
Cancel