Example: View view_basic knowledge in the Backbone. js framework of JavaScript

Source: Internet
Author: User
This article mainly introduces the example of JavaScript Backbone. view view in the js framework. In the browser-side js framework backbone, we use View to bind and handle DOM events, you can refer to the View in Backbone to reflect the Model in your app. They listen to events and respond accordingly.
In the next tutorial, I will not tell you how to bind the Model and Collection to the View, but mainly discuss how the View uses the javascript template library, especially Underscore. js's _. template.
Here we use jQuery to operate DOM elements. Of course you can also use other libraries, such as MooTools or Sizzle. However, jQuery is recommended in official documents of Backbone.
Next, we will use the search box as an example to create a new View:

SearchView = Backbone.View.extend({  initialize: function(){    alert("Welcome to Backbone!");  }});var search_view = new SearchView();

Whether it is Model, View or Collection, the initialize () method is automatically triggered when it is instantiated.

El attributes
The el attribute refers to a DOM object that has been created in the browser. Each View has an el attribute. If it is not defined, backbone creates an empty p element as the el attribute.
Next let's create an el attribute for the View and set it to # search_containe.

Related Article

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.