2

我有一个使用 mers ( https://github.com/jspears/mers ) 运行的休息服务。

现在我想将它连接到backbone.js

问题是 mers 返回包含在有效负载数组中的集合以及附加信息:

例如

{"payload":[
{"_id":"4fe3773ffca7f74410000001","pos":[48.123447013691425,11.57250838808296],"username":"AyKarsi","pictures":[],"images":[],"roles":[],"meta":{},"groups":[]},
{"_id":"4fe3773ffca7f74410000002","pos":[0,3444],"username":"TestUpdateFromClient","pictures":[],"images":[],"roles":[],"meta":{},"groups":[]},],
"status":0,"total":5}

这个信息很好,但是我如何告诉骨干集合它应该在哪里寻找模型?

4

1 回答 1

3

您需要覆盖parse.Backbone.Collection

var MyCollection = Backbone.Collection.extend({
    parse: function(models) {
        return models.payload;
    }
}

这是Backbone.js 网站上的相关文档。

于 2012-06-22T16:29:24.207 回答