-
Book Overview & Buying
-
Table Of Contents
Getting Started with Knockout.js for .NET Developers
By :
Knockout.js allows you to write your own custom functions to extend the capabilities of a standard Knockout.js object. The following objects from the Knockout.js hierarchy can be extended:
ko.subscribable (root object)
ko.computed (inherited from ko.subscribable)
ko.observable (inherited from ko.subscribable)
ko.observableArray (inherited from ko.observable)
If you write a custom function for an object, the inheritors of the object will also have the written function. For example, you can use a custom function of ko.observable with ko.observableArray.
Let's learn how to write a custom function with the following example. We will write the filterByProperty function for ko.observableArray. This function will filter the original array and keep only those items for which the specified property is equal to the specified value. The function body is as follows:
ko.observableArray.fn.filterByProperty = function(propName, matchValue) {
return ko.computed...
Change the font size
Change margin width
Change background colour