所以我的 Backbone.js 代码正在获取 JSON ......我试图在 fetch 方法的成功回调中简单地控制模型,但我只是返回 [r,r,r] 而不是 [object,object,object ]。拔我的头发...
var Person = Backbone.Model.extend();
var PersonCollection = Backbone.Collection.extend({
model : Person,
url: 'js/names.json',
parse: function(data) {
console.log(data); // <--- this will return what I am looking for
return data;
}
});
var PersonView = Backbone.View.extend({
initialize: function(){
var self = this;
self.collection = new PersonCollection();
self.collection.fetch({success: function() {
console.log(self.collection.models); // <-- how do I get it here?
}});
}
});
var newView = new PersonView();
JSON
[
{ "name": "Linda", "birthYear": 1947},
{ "name": "Kat", "birthYear": 1977},
{ "name": "Jen", "birthYear": 1989}
]
编辑:当我在集合中的自定义解析方法中控制台记录数据时,我想要在获取之后得到同样的东西。请参阅上面代码中的注释