There are several problems with your fiddle:
- You bind to values instead of observables. When you write
<input type="text" data-bind="value: global.filterViewModel().Name()" placeholder="Filter by Name"/>
ko uses the value ofglobal.filterViewModel().Name
not the observable. Thus there is no real binding (updating ko will not update the interface, updating the interface will not update ko). You need to remove the last parenthesis:global.filterViewModel().Name
- You put Name instead of Code and vice versa in the binding
- You subscribed to FilterViewModel's changes, but not it's child observable changes. To do this, include the evaluation of the child observables in your computed observable:
-
self.filteredCollection = ko.computed(function () {
var filter = FilterViewModel();
if (filter.Name() != 'testname')
alert("name");
if (filter.Code() != 'testcode')
alert("code");
if (filter.Number() != 'testnumber')
alert("number");
}),
You can test here http://jsfiddle.net/b37tu/1/