Book Image

WEB APP TESTING USING KNOCKOUT.JS

By : Roberto Messora
Book Image

WEB APP TESTING USING KNOCKOUT.JS

By: Roberto Messora

Overview of this book

Table of Contents (11 chapters)

Automatic synchronization between View and ViewModel


In the previous section, we saw a simple example. Now we need to go further to introduce some new concepts. The following example refines the first one:

<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <title>Hello Knockout.JS</title>
</head>
<body>
    <span>Type a message:&nbsp;</span>
    <input type="text" data-bind="value: message" />
    <button data-bind="click: submitMessage">Click me</button>
    <script type="text/javascript" src="http://cdnjs.cloudflare.com/ajax/libs/knockout/3.1.0/knockout-min.js"></script>
    <script type="text/JavaScript">
        var ViewModel = function () {
            this.message = ko.observable("");
            this.submitMessage= function () {
                alert(this.message());
            };
        };
        var viewModel = new ViewModel();
        ko.applyBindings(viewModel...