0
votes

I found this tutorial for a knockout utilty that filters through an array and creates a new filtered version of the array. http://www.knockmeout.net/2011/04/utility-functions-in-knockoutjs.html

From there, I understand that the this.filter in "this.filter().toLowerCase();" is the ko.observable bound to the input box in the view.

I tried to integrate this into my code. I am aware I need more changes. The method "ko.utils.stringStartsWith" is not supported any longer

I am getting the error "Uncaught TypeError: this.kofilter is not a function" I am not sure what that means, is there something wrong with the data binding?

This is my JS code

this.filteredItems = ko.computed(function() {

console.log(this)

var filter = this.kofilter().toLowerCase();

   if (!filter) { 
    return self.venueList(); 
         } else { 
                  return ko.utils.arrayFilter(this.venueList(), function(venues) {
          return ko.utils.stringStartsWith(venues.name().toLowerCase(), filter) ;
      });
  }
}, this.venueList);



};

And this is the HTML

       <br><input placeholder = "Search..." data-bind="value: kofilter, valueUpdate: 'afterkeydown'">
2
Post the line where you create kofilter. And indent your code correctly, that's impossible to read. - Matti Virkkunen
I found the issue, I was missing self.kofilter = ko.observable(''); - d_wesseling

2 Answers

0
votes

I'm willing to bet it's yet again a problem with this. For instance I don't think you want to pass this.venueList to the computed as the context object, but rather just this.

If you have a self variable, stick to that, and don't use this. Otherwise make sure you pass the correct this argument to all the function calls.

0
votes

I found the issue, I was missing self.kofilter = ko.observable('');