Why can't I create Backbone.Collection Backbone.Views?

TL; DR, question below. I solved my problem, but, having typed all this, I still thought that I would throw away the main question.

For those looking for this error, here's a description / solution:

I get an error when trying to add a view to the collection:

Uncaught TypeError: Object [object Object] has no method '_validate'

I solved my problem:

I defined my collection to use a model that was really View:

ViewCollection = Backbone.Collection.extend({ model: MyView });

MyView was an instance Backbone.View, not a model, duh.

Conceptual Question:

Can it be used Backbone.Collectioninstead of arrayor objectfor storing things like Backbone.Collectionof Backbone.Views, or any common array of objects? If my model has several types, usually store them like this:

model
    collectionOfViews
        view
        view
        view
+2
1

. , . .

Backbone Collection:

.

, . , , .

0

All Articles