The principle of backbone
Backbone is designed to add schemas to a single page application, especially when creating Documentcloud applications to avoid repetitive dom crossings and confusing data in the DOM used to keep UI synchronized. The backbone completes this step through a set of constructors, thus forming a model, collection, and view object to organize the application's data, logic, and display. Once these objects are materialized, they have a special relationship with each other, ensuring that the application is modular, loosely coupled (using event system communication) and extensible.
Backbone provides an application architecture and can also help build SPAs
In addition to the Backbone.model (),backbone.collection (), and Backbone.view ( ) constructors (that is, the meat ), backbone also includes the following features for building SPAs and RESTful JSON API Data Preservation:
- Provide router logic (ie backbone.router), so when the URL changes will cause some specific functions;
- Provides router history logic (i.e. backbone.history) so that when a user clicks the browser back or forward button, the path is guaranteed to be correct. Note that this is a single page application and does not contain traditional URLs;
- Provides synchronization logic (i.e. backbone.sync), which is designed to read and store data to the server;
- Provide event system (i.e. backbone.event), use custom event and event listener to realize communication between models, views, collections ;
- provides JavaScript library (i.e. underscore.js or lo-dash.js).
Before you have a deep understanding of models,collections, views, please understand these helpful features. In fact, this is one of the things that this tutorial focuses on.
The conditions on which backbone depends
It is essential for backbone documentation to use the functional programming utility library, eitherunderscore.js or lo-dash.js . Do not have to tangle which one is better, the decisive choice its use is, if does not need words backbone can not work normally. If you can't make up your mind, I'll tell you to use lo-dash.js.
In addition to underscore.js or lo-dash.js libraries, backbone relies on json2.js, as well as jQuery, Zepto , or one of the three Ender (anyone who imitates the jQuery API can work). If the browser does not contain these libraries or does not support windows. JSON, the backbone.router (), Backbone.view (), Backbone.history ( ), Backbone.sync () are not working correctly. This means that without the support of these libraries, the models and collections in backbone can only play a part. However, such cases are rare. I think most of the time, library is are included in the backbone.js (depending on what browser support you need).
The following example HTML file shows the specific manifestations of backbone dependencies:
-
-
-
-
- < script> < li>