Skip to content

Instantly share code, notes, and snippets.

@smykes
Created June 15, 2013 14:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save smykes/5788321 to your computer and use it in GitHub Desktop.
Save smykes/5788321 to your computer and use it in GitHub Desktop.
Question is in a comment of line 25 of models.js.
var AppRouter = Backbone.Router.extend({
routes: {
"" : "list",
"clients/:id" : "clientDetails"
},
initialize: function () {
},
list: function(page) {
$('#header').html(new HeaderView().render().el);
var clientList = new ClientCollection();
clientList.fetch({success: function(){
$("#content").html(new ClientListView({model: clientList}).el);
}})
},
clientDetails: function (id) {
var taskList = new TaskCollection({id: id});
$('#header').html(new HeaderView().render().el);
taskList.fetch({
success: function(data){
$("#content").html(new TaskListView({model: taskList}).el);
},
error: function() {
alert("error");
}
})
}
});
app = new AppRouter();
Backbone.history.start();
window.Client = Backbone.Model.extend({
urlRoot: "api/client_list",
defaults: {
id: null,
name: null,
city: null,
state: null
}
});
window.ClientCollection = Backbone.Collection.extend({
model: Client,
url: "api/client_list"
});
window.Task = Backbone.Model.extend({
urlRoot: "api/client/",
defaults: {
id: null
}
});
window.TaskCollection = Backbone.Collection.extend({
model: Task,
url: "api/client/" //How do I append the ID to this URL?
});
@BorisKozo
Copy link

Remove line 17
urlRoot: "api/client/"
urlRoot is needed only if the model is not in a collection

@BorisKozo
Copy link

Another solution is to override the url function on the model and return "api/client/"+this.id but for this example my previous comment is a better solution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment