I am filtering two drop downs using Knockout and I don't know why im seeing this console error.
Uncaught TypeError: Unable to process binding "value: function(){return $root.filter }" Message: Cannot read property 'length' of undefined
The issue is related to the return value, it filters the data correctly; However, console error keeps appearing, I've tried changing the following:
- Changing
$rootto$data - Changing
filter.Valuetofilter.ID() - Removing the brackets, just returning ID, and so far nothing is working?
The JS/Knockout:
var self = this;
self.filters = ko.observableArray(self.Model.Teams());
self.filter = ko.observable('');
self.items = ko.observableArray(self.Model.Users());
self.filteredItems = ko.computed(function () {
var filter = self.filter();
if (!filter || filter == "All") {
return self.items();
} else {
return ko.utils.arrayFilter(self.items(), function (i) {
return i.ID() == filter.Value();
});
}
});
This select dropdown:
<div>
<select class="filter-dropdown-small" data-bind="options: $root.filters, value: $root.filter, optionsText: 'Text', optionsCaption: 'All'"></select>
</div>
Filters this one:
<div>
```<select class="filter-dropdown-small" data-bind="options: $root.filteredItems, optionsText: 'Text', optionsCaption: 'All'"></select>```
</div>
The data to filter with no console error.