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

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.

主站蜘蛛池模板: 化州市| 庐江县| 宜春市| 分宜县| 平利县| 济源市| 无棣县| 清远市| 青岛市| 宜丰县| 宁津县| 定南县| 循化| 湘西| 息烽县| 高淳县| 泰州市| 蛟河市| 马公市| 石城县| 清流县| 光泽县| 咸宁市| 大英县| 什邡市| 莫力| 郑州市| 临海市| 满洲里市| 隆化县| 长汀县| 西乌珠穆沁旗| 江永县| 新蔡县| 漾濞| 准格尔旗| 石渠县| 云和县| 元阳县| 崇左市| 青冈县|