官术网_书友最值得收藏!

Chapter 2. Working with Views

Backbone view works as the presentation layer of an application. In simple terms, you can define it as an abstract layer for your HTML element. It doesn't contain any HTML markup of its own, but it contains the logic to present your model's data with the help of JavaScript templates.

If you go through the annotated source of Backbone view, you will find that Backbone.View is a small class with very few methods, including an empty initialize() method and an almost empty render() method, which are in general meant to be overridden by any custom view class. In this chapter, we will investigate some common problems and the solutions to these problems with respect to the Backbone views that developers face mostly while developing real-world Backbone.js applications.

The basic issues with Backbone are associated with view rendering or updating and maintaining multiple views within an application. We will analyze the following topics based on complexity:

  • Basic usage of views: We will learn the basic concepts of Backbone view, its properties, functions, and event-handling.
  • Updating a view partially: We will learn how to update only a part of a view without the need for re-rendering the complete view.
  • Nested views: As the complexity of an application layout increases, we feel the need to maintain a hierarchy of multiple views. Nested views or subviews simplify event-handling and layout management to a great extent. We will explore the following topics:
    • When we need to use subviews
    • How to initialize and render nested views
    • How to avoid DOM reflow in the case of a large collection of nested views and a complex view DOM structure
    • How to clean up resources (child views, events) when you delete a parent view
  • Templates: Templates are an essential part of Backbone and are used in combination with views to create reusable copies of HTML markup. We will discuss the following topics:
    • The different options for storing and loading template files
    • The advantages of template precompilation and storing precompiled templates on the client side
    • The usage of template helper functions
  • Marionette views: We can reduce the view boilerplate code using the custom view extensions of the Marionette library.
  • Layout manager: We can simplify the complex layout architecture using the Backbone layout manager plugin.
主站蜘蛛池模板: 德清县| 江安县| 西丰县| 万山特区| 彭阳县| 蒙自县| 塔城市| 改则县| 彰化市| 织金县| 山东省| 奉新县| 奉贤区| 米泉市| 安溪县| 砀山县| 榆中县| 清丰县| 宁蒗| 封开县| 邵阳市| 罗甸县| 延边| 定西市| 清水县| 英德市| 喜德县| 益阳市| 石景山区| 灵宝市| 南木林县| 靖江市| 昌图县| 灵台县| 达日县| 宜良县| 金沙县| 会理县| 道孚县| 宣化县| 肇州县|