Skip to content

Instantly share code, notes, and snippets.

@joshnesbitt
Created May 17, 2012 15:11
Show Gist options
  • Select an option

  • Save joshnesbitt/2719553 to your computer and use it in GitHub Desktop.

Select an option

Save joshnesbitt/2719553 to your computer and use it in GitHub Desktop.
// Listing bookmarks with a collection:
var BookmarksCollection = SignalBox.Backbone.Collection({
resource : 'bookmarks'
});
var bookmarks = new BookmarksCollection;
bookmarks.fetch({
success : function(collection){
console.log("success: " + collection.length + " records found.");
}
});
// Creating a bookmark with a model:
var BookmarkModel = SignalBox.Backbone.Model.extend({
resource : 'bookmarks'
});
var bookmark = new BookmarkModel({});
bookmark.save({ url : 'https://getsignalbox.com' }, {
success : function(model, attributes){
console.log("created", model.id);
}
});
// Reading a bookmark record:
bookmark.fetch({
success : function(model, attributes){
console.log('found', attributes);
}
});
// Updating an existing bookmark:
bookmark.save({ url : 'https://docs.getsignalbox.com' }, {
success : function(model, attributes){
console.log("updated", attributes);
}
});
// Deleting a bookmark:
bookmark.destroy({
success : function(model){
console.log('destroyed', model.id);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment