我试图从一个JSON网址提取的集合。 骨干确实发送请求并不会得到回应,但没有任何models
后,集合中:
这里是我的JavaScript:
stores.fetch();
JSON的响应
[{"name":"Store 1"},{"name":"Store 2"},{"name":"Store 3"},{"name":"Store 4"}]
在响应中的Content-Type HTTP头是application/json
。
为什么不把它加载到集合? 是JSON正确的吗?
一些更多的代码:
be.storeList.Item = Backbone.Model.extend({
defaults: {
id: null,
name: null,
description: null
},
initialize:function(attrs){
attrs.id = this.cid;
this.set(attrs);
}
});
be.storeList.Items = Backbone.Collection.extend({
model: be.storeList.Item,
url:'/admin/stores'
});
var stores = new be.storeList.Items();
stores.fetch();
console.log(stores.toJSON());