customBinding sample
by shriek
HTML
<p>First name: <strong data-bind="test:{}, text:firstName">todo</strong>
</p>
<p>Last name: <strong data-bind="text:lastName">todo</strong>
</p>
<p>First name:
<input type="text" data-bind="value:firstName" />
<p>Last name:
<input ttype="text" data-bind="value:lastName" />
JavaScript
// This is a simple *viewmodel* - JavaScript that defines the data and behavior of your UI
function AppViewModel() {
this.firstName = ko.observable("Bert");
this.lastName = ko.observable("Bertington");
}
// Activates knockout.js
ko.applyBindings(new AppViewModel());
ko.bindingHandlers.test = {
init: function () {
alert("hi");
},
update: function () {
alert("bye");
}
};