Backbone.js Series Tutorial Four: Backbone Comprehensive introduction

Source: Internet
Author: User
Tags add object constructor event listener functions json client cloudflare

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:

 
 
    1. < script> < li>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.