• About

Information Dynamics

Information Dynamics

Category Archives: Knockout and TypeScript

MVVM Framewok using Knockout.js

23 Thursday Jan 2020

Posted by GIRISH SRINIVASA in Knockout and TypeScript

≈ Leave a comment

Tags

Knockout, MVVM, TypeScript

The purpose of knockout.js is to bind UI elements to underlying data model so changes made are updated to model immediately and vice versa. So compared to traditional javascript code where element values are explicitly set through code knockout relies on binding mechanism. It uses a declarative approach where the elements on the page are bound to properties of an ViewModel object.

Two main principles of Knockout are Observables and Bindings.

Scenario 1:

A sample one-way data bind to display text will look like the following

Knockout1

At high level the step(s) for the above are:

  • Reference knockout.js
  • Use data-bind attribute indicating the property name of the object. In the example above it is authorName
  • Initialize a viewModel object with a single property authorName value set to ‘Girish Srinivasa’
  • Use applyBindings methods passing in the viewModel object

Scenario 2:

In the following example the authorName property of the ViewModel object is changed when the the value in the text box is changed.

Knockout2

  • data-bind=”text…” will render a label control
  • data-bind=”value…” associated with <input tag will render a text box control

Change the value in text box control to Girish Srini and notice that the label still displays Girish Srinivasa

Knockout3

This is because there is notification to indicate that the ViewModel object property authorName requires updating. This can be corrected by the using observables that will have ViewModel object properties automatically updated as shown in the following snap shots.

On Initial Load

Knockout4

After changing the value in the text box

Knockout5

 

 

Subscribe

  • Entries (RSS)
  • Comments (RSS)

Archives

  • November 2021
  • August 2021
  • July 2021
  • July 2020
  • June 2020
  • May 2020
  • April 2020
  • March 2020
  • February 2020
  • January 2020
  • December 2019
  • October 2019
  • September 2019
  • August 2019
  • July 2019
  • March 2019
  • September 2018
  • February 2018
  • January 2018
  • December 2017
  • January 2017
  • August 2016
  • January 2016
  • November 2015
  • October 2015
  • September 2015
  • November 2014
  • October 2014
  • September 2014
  • July 2014

Categories

  • ADCS
  • ADFS
  • ADFS 4.0
  • ASP.NET Core
  • Azure
  • Azure AD
  • Azure AD DS
  • Azure B2C
  • CRM 2011
  • CRM2013
  • CRM2015
  • CRM2016
  • Docker
  • Dynamics 365
  • Dynamics 365 CE Online
  • Dynamics 365 Portals
  • Dynamics CE 9
  • Knockout and TypeScript
  • OAuth2.0/OpenIDConnect
  • Power Platform
  • PowerApps
  • PowerShell
  • SharePoint 2019
  • Spkl
  • Uncategorized
  • WebAPI
  • Windows Server 2012
  • Windows Server 2016

Meta

  • Register
  • Log in

Blog at WordPress.com.

  • Follow Following
    • Information Dynamics
    • Already have a WordPress.com account? Log in now.
    • Information Dynamics
    • Customize
    • Follow Following
    • Sign up
    • Log in
    • Report this content
    • View site in Reader
    • Manage subscriptions
    • Collapse this bar
 

Loading Comments...