backbone-parse overrides the Backbone.Sync method to automatically persist your backbone models on Parse using their REST API. Saving you from all the manual plumbing.
Download backbone-parse.js and include it in your application after backbone.js e.g.
<scriptsrc="backbone-min.js"></script><scriptsrc="backbone-parse-min.js"></script>Open backbone-parse.js and replace following at the top with your Parse credentials:
varapplication_id="CkWCHMSOgyqoNKoIc5hu09uvdZcJ9rpHJD4iwhxI";varrest_api_key="H5SIwarTRXqd07C0OIZPbcRTYTNLKsjFAJt5PrFY";varapi_version="1";Create a Backbone model and set the parse class name:
varItem=newBackbone.Model({_parse_class_name: "Item";});Similarly for Collections:
varItemsCollection=newBackbone.Collection({_parse_class_name: "Item";});This class name will specify backbone-parse which class persists this model on the Parse server. It is case sensitive. If the class doesn't already exists, Parse will automatically create one.
If the class name is not specified, then the model will be persisted using the default Backbone Sync (i.e. you'll need to specify a url)
Parse.com provides an API to query your data.
backbone-parse provides an easier method for specifying query constraints*. All you need is to pass the constraints in fetch method of Backbone.Collection. e.g.
varItemCollection=newBackbone.Collection({_parse_class_name: "Item"});varitems=newItemCollection();items.fetch({query: {"in_stock":true}});This will fetch all the items which are in stock. For details about what constraints you can pass, read: https://parse.com/docs/rest#queries
Feedback welcome.
- tests(!)
- extend Backbone.Model to tackle Parse User objects
Distributed under MIT license.
*inspired by: http://houseofbilz.com/archives/2011/11/07/making-backbone-js-work-with-parse-com/