I'm looking to fetch a subset of a backbone collection using the model's URL. Similar to the tutorial of "Nested Collections" found at:
http://liquidmedia.org/blog/2011/01/backbone-js-part-1/
Since this requires data api, models, collections, views i've included my full code of what Im trying to create:
Code (In Node/Mongoose/Express/Rest): https://github.com/1manStartup/Backbone-URLRoot
Live Example (on my ec2): http://54.251.104.185/
I believe my problem lies somewhere with the rendering of views and fetching of model data.
What Im Trying To Do: Render all Articles Unique to Dog. Route Is: /api/makearticle/:id
If you don't use NodeJs, my JSON Api looks like this:
{
"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
},
Here are my models and Collections: Rest of backbone code found at: 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 ;
}
});
Please Help ive been on this for several days. Thanks.
/api/dogs/3/articles
) that will return the list of articles related to a given dog. Then, simply load that data in a collection and use a collection/composite view to display. – David Sulc