【发布时间】:2018-05-20 14:54:22
【问题描述】:
我在handling collection 上遇到了堆栈溢出问题。 Brian Genisio 给出的答案非常有说服力。我试过他的方法如下:
集合定义
var PersonCollection = Backbone.Collection.extend({
model : Person,
url: '/people',
parse: function(resp, xhr) {
this.header = resp.header;
this.stats = resp.stats;
return resp.people;
}
});
收集使用情况
var personCollection = new PersonCollection();
personCollection.fetch();
console.log(personCollection.header); //undefined
console.log(personCollection.status); //undefined
该集合完美地获取模型,但我将其他分配的属性设置为未定义。请建议我解决此问题的解决方案。
【问题讨论】: