0

I have a model fetch from a JSON file.

var TemplateModel = Backbone.Model.extend ({

    // JSON URL
    urlRoot: 'json file url',

    // Fetch on initialize.
    initialize:function startModel(){
        this.fetch();
    },
    // Defaults
    defaults: {
        /** Defaults. **/
    }
});

The thing i want to do is to get some Array of objects from the json fetched and load this array to a collection.

var templatesModel = new TemplateModel();
var constants =  templatesModel.get('constants');
var constantsCollection = new Backbone.Collection.extend({model: constants});

But i receive multiple errors.

¿Any idea how can i filter a model and fill with the filtered data a Collection?

Thanks in advance

DiegoKTC
  • 9
  • 5

1 Answers1

0

What kind of errors? Can you show console log?

And:

var constantsCollection = new Backbone.Collection.extend({model: constants});

In this example you define type for models in this collection, and i think this causes errors. If you want to fill collection with models from array try this:

 var constantsCollection = new Backbone.Collection.extend(constants);
  • Thank you, this was the answer, i have to fill my collection like you said. I was declaring a model from a already declared and fetched model. Thank you. – DiegoKTC Nov 11 '13 at 20:59