This is my javascript: <script src="../Scripts/knockout-3.0.0.js"></script> <script type="text/javascript"> alert("hiii"); function AppViewModel() { this.firstName = ko.observable("Amol"); this.lastName = ko.observable("Padher"); this.fullName = ko.computed(function () { return this.firstName() + " " + this.lastName(); }, this); this.capitalizeLastName = function () { var currentVal = this.lastName(); // Read the current value this.lastName(currentVal.toUpperCase()); // Write back a modified value }; } // Activates knockout.js ko.applyBindings(new AppViewModel()); </script>
Below the html code: <body> <form id="form1" runat="server"> <div> <!-- This is a *view* - HTML markup that defines the appearance of your UI --> <p>First name: <strong data-bind="text: firstName"></strong></p> <p>Last name: <strong data-bind="text: lastName"></strong></p> <p>First name: <input data-bind="value: firstName" /></p> <p>Last name: <input data-bind="value: lastName" /></p> <p>Full name: <strong data-bind="text: fullName"></strong></p> <button data-bind="click: capitalizeLastName">Go caps</button> </div> </form> </body> How to run the above code using Knockout? I.e. how to call the function AppViewmodel() in this program? please sugguest me any solution!!
i got the solution. and it is-
$(document).ready(function (){ // Activates knockout.js ko.applyBindings(new AppViewModel()); })
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)