Attempting to populate a collection from a list of values, I get the error message β model prototype undefined collection. Considering this issue of a similar problem , I checked that the model was actually created before the collection was installed as much as possible.
The error is raised in one of the Marionette CompositeView event handlers, which contains the collection, after collecting data from the server and tries to reset collection with a list of values ββfrom the data that must be filled into it.
Note. Using Backbone 0.9.10
Model
MyItemModel = Backbone.Model.extend({});
Collection
MyCollection = Backbone.Collection.extend({ model: MyItemModel });
Corresponding CompositeView Code
MyCompositeView = Backbone.Marionette.CompositeView.extend({ initialize: function(options) { _.bindAll(this); this.model = new MyCompositeViewModel(); this.collection = new MyCollection(); }, //This event handler gets properly fired and run. on_event: function() { var that = this; // The data comes through fine with this `fetch` this.model.fetch({success: function() { var collection_results= that.model.get("collection_results"); // The error fires in this line that.collection.reset(collection_results); that.render(); }); } })
Mistake
An error in the add function in the Backbone when executing get on a model object, checking if it is a duplicate The error code is here:
// Get a model from the set by id. get: function(obj) { if (obj == null) return void 0; // The error originates from this line this._idAttr || (this._idAttr = this.model.prototype.idAttribute); return this._byId[obj.id || obj.cid || obj[this._idAttr] || obj]; }, this._idAttr || (this._idAttr = this.model.prototype.idAttribute);
Here this.model.prototype.idAttribute fails because prototype not defined for the model.
Why is this happening, and how can this be fixed?
Thank you so much!
Juan Carlos Coto
source share