Backbone.Collection.fetch throws "The object [...] does not have a method '_validate'"

I have a simple Backbone collection that pulls a list of objects from a (remote) resource. The call Collection.fetch, however, does not complete with this error:

Object [object Object] has no method '_validate'

I assume this happens under the hood when the collection tries to instantiate a model for each JSON object when added. Can anyone shed some light on why this will happen?

Here is the code I'm using. Very bare bones ...

/* Models */

var SomeModel = Backbone.View.extend({});


/* Collections */

var SomeCollection = Backbone.Collection.extend({
    url: 'http://localhost:8000/api/some/resource/?format=json',
    model: SomeModel,

    parse: function(data) {
        return data.objects
    }
});

var SomeView = Backbone.View.extend({
    collection: new SomeCollection(),

    initialize: function() {
        this.collection.fetch();
    },
});

And here is an example of a resource response:

{
  "meta": {
    "count": 100
  },
  "objects": {
    {"title": "Title", "id": 1},
    {"title": "Title 2", "id": 2}
  }
}
+3
source share
1 answer

, model Basebone.Model. , set, _validate, Backbone.Model, . . Backbone.Collection.fetch.

. . SomeModel View model. - // .

var SomeModel = Backbone.View.extend({});
+15

All Articles