Introduction to the MVC structure design concept of the Backbone. js framework of JavaScript _ basic knowledge

Source: Internet
Author: User
This article mainly introduces the MVC structure design concept of the Backbone. js framework of JavaScript. compared with Angular. js, the Backbone with the same MVC structure is much lighter. if you need it, you can refer What is Backbone. js?
Backbone. js is the first of the top ten JS frameworks. Backbone. js is a heavyweight js MVC application framework and also the originator of the js MVC framework. It uses the Models data model for key-value binding and custom event processing, and uses the model collection tool Collections to provide a rich set of APIs for enumeration, view Views are used to process events and interact with existing applications through the JSON interface.

In short, Backbone is a js library that implements the web front-end MVC mode.

What is MVC?
MVC: the backend server first (process 1) obtains the page address through the browser, parses the URL, obtains a URL for the View, and then parses it through the controller, then, find the corresponding data (Process 2), find the data, and then return the data Model to the controller (process 3). then, the controller processes the data, return to View (Process 4), that is, update View. This structure is very clear and easy to implement at the backend.

MVC mechanism in Backbone
Backbone presents the data as a model. you can create a model, verify and destroy the model, and even save it to the server. When the model attribute changes due to changes in the UI, the model triggers the "change" event. all views that display model data receive notifications of this event, and the view is re-rendered. You do not need to search the DOM to search for the elements with the specified id to manually update the HTML. -When the model changes, the view automatically changes. --- Baidu Encyclopedia

Mode: a common solution to the problem

-Design mode: Factory mode, Adapter mode, and observer mode
-Framework mode: MVC, MVP, and MVVM
Controller: connects views and models through controllers.

The idea of MVC mode:

Is to separate the model from the view and connect them through the controller.
The MVC mode on the server is very easy to implement.
Model: Model refers to data. Model is the core of all js applications, including interactive data and a large number of related logic: conversion, verification, calculation attributes, and access control. You can extend Backbone. Model in a specific way.

View: View that you can see on the page. Each single data model corresponds to a View

The web page itself is a large view, and it is not easy to perform separation operations. backbone. js is suitable for complicated large-scale development and solves these problems for us.

Backbone module
Backbone has the following modules:

  • Events: Event-driven module
  • Model: Data Model
  • Collection: Model set
  • Router: Router (corresponding to hash value)
  • History: enables History management.
  • Sync: synchronous server mode
  • View: View (including event behavior and rendering page-related methods)

Collection is a unified control of individual data models.

Directly create an object
Backbone depends on Underscore. js, DOM processing depends on Backbone. view and jQuery. before js, Underscore. js must be introduced before it, while jQuery is also better to introduce it together, and then introduce Backbone. js

  
     

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.