-
-
Save BorisKozo/5789198 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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([],{clientId: 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(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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({ | |
defaults: { | |
id: null | |
} | |
}); | |
window.TaskCollection = Backbone.Collection.extend({ | |
model: Task, | |
initialize: function(models, options){ | |
this.options = options; | |
}, | |
url: function(){ return "api/client/"+this.options.clientId;} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment