1. Basic viewmodel and observableArray

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script type='text/javascript' src='knockout-3.4.0.js'></script>


</head>
<body>
The name is <span data-bind="text: personName"></span>
The age is <span data-bind="text: personAge"></span>
The funll name is <span data-bind="text: fullName"></span>

</body>
</html>
<script>

    var myViewModel = {
        personName: ko.observable('Bobw'),
        personAge: ko.observable(123)
    };

ko.applyBindings(myViewModel);


var anotherObservableArray = ko.observableArray([
    { name: "Bungle", type: "Bear" },
    { name: "George", type: "Hippo" },
    { name: "Zippy", type: "Unknown" }
]);



    alert('The length of the array is ' + anotherObservableArray().length);
    for(var i=0; i< anotherObservableArray().length ;i++)
    {
        alert('The name  is ' + anotherObservableArray()[0]['name']+" type is "+ anotherObservableArray()[0]['type']);
    }




function AppViewModel() {
    this.firstName = ko.observable('Bob');
    this.lastName = ko.observable('Smith');
    this.fullName = ko.pureComputed(function() {
        return this.firstName() + " " + this.lastName();
    }, this);
}

    ko.applyBindings(AppViewModel());

</script>

Leave a Comment