我有一个运行mers的rest服务(https://github.com/jspears/mers)。
现在我想把它连接到backbone.js
问题是,mers返回包装在payload数组中的集合,其中包含附加信息:
例如

{"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}

这些信息是很好的,但我如何才能告诉主干收集应该在哪里寻找模型?

最佳答案

您需要覆盖parse中的默认Backbone.Collection函数。

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

这是backbone.js网站上的relevant documentation

关于node.js - 结合使用mers和elegate.js,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/11159179/

10-12 06:34