0

我从 JSON 文件中获取模型。

var TemplateModel = Backbone.Model.extend ({

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

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

我想做的事情是从获取的json中获取一些对象数组并将这个数组加载到一个集合中。

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

但我收到多个错误。

¿ 知道如何过滤模型并用过滤后的数据填充集合吗?

提前致谢

4

1 回答 1

0

什么样的错误?你能显示控制台日志吗?

和:

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

在此示例中,您为此集合中的模型定义类型,我认为这会导致错误。如果你想用数组中的模型填充集合,试试这个:

 var constantsCollection = new Backbone.Collection.extend(constants);
于 2013-11-11T20:37:50.170 回答