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

  • Mastering KnockoutJS
  • Timothy Moran
  • 219字
  • 2021-08-05 17:13:11

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.

主站蜘蛛池模板: 舞阳县| 都匀市| 包头市| 运城市| 青浦区| 新乡市| 柳河县| 长岛县| 会昌县| 高唐县| 青阳县| 应用必备| 繁昌县| 航空| 电白县| 上犹县| 涞水县| 靖远县| 安康市| 弋阳县| 彰武县| 新沂市| 易门县| 云和县| 额济纳旗| 淳安县| 章丘市| 法库县| 枣阳市| 鄂伦春自治旗| 垣曲县| 正宁县| 微博| 凤庆县| 东阳市| 广饶县| 运城市| 西宁市| 怀宁县| 堆龙德庆县| 普格县|