backbone.jsHow do I create and use stores in a Backbone.js application?
Creating and using stores in a Backbone.js application is done by creating a Model or Collection and then setting the localStorage property on it.
For example, to create a Model with localStorage and save it:
var Todo = Backbone.Model.extend({
localStorage: new Backbone.LocalStorage("todo-store")
});
var todo = new Todo({name: "My Todo"});
todo.save();
To use the stored values, you can call fetch() on the Model or Collection:
todo.fetch();
The parts of this code are:
var Todo = Backbone.Model.extend({- creating a Backbone ModellocalStorage: new Backbone.LocalStorage("todo-store")- setting the localStorage property on the Modelvar todo = new Todo({name: "My Todo"});- creating a new instance of the Modeltodo.save();- saving the Model to localStoragetodo.fetch();- fetching the Model from localStorage
Helpful links
More of Backbone.js
- ¿Cuáles son las ventajas y desventajas de usar Backbone.js para el desarrollo de software?
- How can I use Backbone.js to customize a WordPress website?
- How can I use Backbone.js with React to build a web application?
- How can I use ES6 with Backbone.js?
- How can I use Backbone.js to validate user input?
- How do I use Backbone.js to create a wiki?
- How can I use Backbone.js to update a view when a model changes?
- How do I use a template engine with Backbone.js?
- How can I use backbone.js to implement zoom functionality?
- How do I use Backbone.js to determine where something is?
See more codes...