You must have a calculated setup to make everything work
View:
<ul data-bind="foreach: { data: PersonData}"> <li> <a data-bind="attr: { data: Filter },visible:Filter!='people'" class="filterbtn"> <span data-bind="html: Name"></span> <span data-bind="text: Age" class="age"></span> </a> </li> </ul> <div data-bind="foreach:data"> <span data-bind="html: Name"></span> <span data-bind="text: Age" class="age"></span> </div>
ViewModel:
var ViewModel = function () { var self = this; self.PersonData = ko.observableArray([{ 'Filter': 'people', 'Name': 'cool', 'Age': '1' }, { 'Filter': 'nope', 'Name': 'cooler', 'Age': '2' }, { 'Filter': 'people', 'Name': 'hotter', 'Age': '3' }]) self.data = ko.computed(function () { return ko.utils.arrayFilter(self.PersonData(), function (item) { return item.Filter === "people";
working script here
source share