Skip to content

Instantly share code, notes, and snippets.

View tauren's full-sized avatar

Tauren Mills tauren

View GitHub Profile
@tauren
tauren / FindUserCollection.js
Created March 22, 2011 22:20
Handling different URLs with backbone.js
var FindUserCollection = Backbone.Collection.extend({
model: User,
baseUrl: "/api/v2/users",
url: function() {
return this.baseUrl + '?' + $.param({
search: this.search,
limit: this.limit
});
}
search: null,
var child = new Backbone.Model({name: "child"});
var parent = new Backbone.Model({name: "parent", child: child});
var json = parent.toJson()
This should return:
{
name: "parent",
child: {
name: "child"
}
var user = new User({
id: 1,
username: "bob",
address: {
id: 1,
street: "232 SW Main"
city: "",
state: "",
zip: ""
}
/*
* REST endpoint: /projects
*/
var projects = [
{
"id": 2,
"name": "Project 1",
"members": [
{"id": 1, "name": "Tom", "phone": "555-5555"},
{"id": 2, "name": "Sue", "phone": "555-5555"}