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

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.

主站蜘蛛池模板: 锡林浩特市| 遵义县| 吉林省| 天长市| 宣化县| 固安县| 长岛县| 临澧县| 镇康县| 中江县| 磐石市| 昂仁县| 通山县| 抚远县| 阳泉市| 合山市| 正镶白旗| 阿巴嘎旗| 江山市| 若尔盖县| 来宾市| 上栗县| 武夷山市| 抚松县| 沂南县| 清流县| 霍邱县| 商城县| 鄂伦春自治旗| 嘉峪关市| 连云港市| 固镇县| 民县| 旬阳县| 灵璧县| 潼南县| 卓尼县| 汾阳市| 嘉峪关市| 兴业县| 碌曲县|