我正在寻找使用模型网址获取骨干网集合的子集。 为“嵌套集合”的教程类似的发现:使用唯一模型URL获取骨干网集合子集
http://liquidmedia.org/blog/2011/01/backbone-js-part-1/
因为这需要数据API,模型,集合,观点我已经包括了我的什么我试着去创造全码:
代码(在节点/猫鼬/快速/垫):https://github.com/1manStartup/Backbone-URLRoot
活生生的例子(在我的EC2):http://54.251.104.185/
我BELI前景我的问题存在于渲染视图和提取模型数据的地方。
我在做什么:呈现所有文章独特的狗。路线为: /API/makearticle /:ID
如果你不使用的NodeJS,我的JSON API就像这样:
{
"articlename": "feed chocolate",
"_dog": {
"name": "pitbull",
"_id": "51d0b9ad6fd59c5059000002"
},
"_id": "51d0c22a6fd59c5059000007",
"__v": 0
},
{
"articlename": "took to vet",
"_dog": {
"name": "chihuaha",
"_id": "51d0b9af6fd59c5059000003"
},
"_id": "51d0c22e6fd59c5059000008",
"__v": 0
},
这里是我的模型和类别: 休息的骨干代码中发现在: https://github.com/1manStartup/Backbone-URLRoot
https://github.com/1manStartup/Backbone-URLRoot/blob/master/public/javascripts/demo-routerurl.js
Dog = Backbone.Model.extend({
idAttribute: '_id',
urlRoot:'/api/makedog' ,
initialize:function() {
this.dogs = new Dogs();
this.dogs.url = this.urlRoot + "/" + this.id ;
}
});
Dogs = Backbone.Collection.extend({
model: Dog,
url: '/api/makedog'
});
Article = Backbone.Model.extend({
idAttribute: '_id',
urlRoot:'/api/makearticle' ,
initialize:function() {
this.merr = new Articles;
this.merr.url = this.urlRoot + "/" + this.id ;
}
});
请帮助香港专业教育学院已经有好几天了。谢谢。
这似乎是更大的API问题:你需要一个API端点(例如'/ API /狗/ 3/articles'),将返回与给定的狗的文章列表。然后,只需将该数据加载到集合中并使用集合/合成视图来显示即可。 –
感谢您的回复。使用我当前的API即可显示集合中所有文章的列表。也创造了像/ API /狗/路由:id其中:身份证被用来识别狗的文章中。林有可能在,即时通讯只能够渲染完整集合,而不是由URL定义的单个模式的集合中取一部分麻烦:ID。 – 1ManStartup
什么是对/ API的API返回/狗/:ID?在上面的代码中,有以下几个狗的文章似乎要返回...... –