Knockout: Updating the ViewModel

Using Knockout.js to dynamically bind events to fields.

In most web applications, the user drives the business process being invoked.
Therefore, it’s necessary to allow them to “fire” events in order to provide the desired functionality.
To illustrate how to integrate an event, I will begin where my last Knockout.js: Computed fields article left off.

As you can see, I’m beginning with enough code to grab the first three values and assign it to “Sales Associate Overview.”

1-knockout-updating-viewmodel

The change I want to happen will double the sales revenue entered so I’ll add a function to achieve that requirement within the ViewModel.

2-knockout-updating-viewmodel

Next, I’ll a button that is bound to the “click” event and executes my doubleRevenue() function.

3-knockout-updating-viewmodel

Now my page contains a button which lets me double the revenue entered when I click it.

4-knockout-updating-viewmodel 5-knockout-updating-viewmodel

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s