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

  • Mastering Backbone.js
  • Abiee Echamea
  • 236字
  • 2021-07-23 14:39:34

Identifying view types

After working with Backbone for a while you can see common use cases for views emerge; they are so common they can be used for different unrelated projects. These views can be extracted and can be used on any project if they are built correctly. Looking at the Backbone documentation, Views do not implement a default render method, so the trick here is to define a set of views with a default render method for different use cases:

  • View with model – Render a template with model data.
  • View with collection – Render a collection of views with collection data; it should update the list of views automatically when the collection changes.
  • Region – This view acts like a container; it points to a particular DOM node and manages the content for that node. It's used to render other views.
  • Layout – A layout is composed of one or more regions; it defines an HTML structure to organize where the regions will be placed.

Figure 2.1 shows a simple wireframe for an application; as you can see, it is a very common layout found on web applications and is very useful to understand how the common view types are related.

Figure 2.1: Views, Regions, and Layout relationship

With these foundation views you will have a simple but powerful framework to manage your views, so you won't need to implement the render() method anymore.

主站蜘蛛池模板: 台南县| 靖江市| 武功县| 美姑县| 邓州市| 赤水市| 石屏县| 张家界市| 衡东县| 定西市| 阳山县| 辽宁省| 天等县| 兴安盟| 永修县| 德州市| 武定县| 什邡市| 平谷区| 阜南县| 沂南县| 久治县| 同江市| 琼中| 塔河县| 霞浦县| 句容市| 连云港市| 靖西县| 紫云| 信丰县| 张家口市| 独山县| 文登市| 嘉兴市| 克东县| 高碑店市| 东丰县| 瑞金市| 台安县| 广西|