So I’m almost done with this guest list front-end application I’ve been working on. The last thing I want to do is allow a string to be passed to filter the list by name. So by subscribing to a user inputting some name into a field, I should be able to use this ko computed function for searching the array in this different way. Keep in mind that self.guests is an array of guest objects.
self.displayResults = ko.computed(function(){
if(self.displayTypeOf() == 'slice'){
var ary = self.guests.slice(self.startValue(),self.endValue());
console.log(ary)
return ary
}else if(self.displayTypeOf() == 'string'){
//Code I need goes here
}
});
You can see that normally the list is computed with a sliced section of the list, when the user begins typing something in the input, I will override and update this computed list using the search array function I’m asking for.
Thanks in advance!
I would recommend to
ko.utils.arrayFilterutility function for filtering:Read more about ko utils methods here: http://www.knockmeout.net/2011/04/utility-functions-in-knockoutjs.html