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

An overview of Knockout

Knockout is a library designed for Model-View-ViewModel (MVVM) development. This pattern, a descendant of Martin Fowler's Presentation model, encourages the separation of User Interface (UI) from the business logic of the domain model. To facilitate this separation, Knockout provides the three necessary components for implementing this pattern, namely, a declarative syntax for the view (the data-bind HTML attribute), a mechanism to notify changes from the viewmodel (the observable object), and a data binder to mediate between the two (Knockout's binding handler).

We will be covering the data-bind and observable object syntax here; the binding handler syntax and its use will be covered in the next chapter.

Using the MVVM pattern means your viewmodel operates on data with JavaScript, and your HTML view is described using the declarative data-binding syntax. Your JavaScript code should not be directly accessing or modifying the view—data-binding should handle that by translating your observable objects into HTML using binding handlers.

The best way to think about the separation between view and viewmodel is to consider whether two different views could use your viewmodel. While this is often not done, it is still helpful to keep it in mind because it forces you to maintain the separation between them. MVVM allows you to redesign the view without affecting the viewmodel.

主站蜘蛛池模板: 新乡市| 桐柏县| 宜昌市| 弋阳县| 静宁县| 石城县| 吉木萨尔县| 仙游县| 荣成市| 高清| 翁源县| 大足县| 涿州市| 威宁| 三穗县| 栖霞市| 健康| 澄江县| 浮山县| 小金县| 玉林市| 泉州市| 镇原县| 通许县| 榆树市| 宜良县| 旅游| 庆元县| 广元市| 沧州市| 瑞昌市| 彭山县| 屏东市| 南投市| 自贡市| 西昌市| 项城市| 张家界市| 图们市| 新源县| 宣城市|