javascript - Creating a new collection inside existing collection -
i trying put backbone model inside existing model. wondering if possible.
var rf = this.collection.create(attrs, options); model.set(table, rf);
thanks
what trying "nested models & collections". backbone has preferable approach. common idea consist in storing of nested model directly in instance of model instead attributes.
so, create child model first , pass parent model through options
following:
var rf = this.collection.create(attrs, options); var model = backbone.model.extend({ initialize: function(attributes, options) { _.isobject(options) || (options = {}); if (options.child) { this.child = new options.child; } } }); var model = new model({}, {child: rf});
if want supported tree-like backbone models try use 1 of following plugins.
hope helps!
Comments
Post a Comment