javascript - Filtering function: use KO struggling -


try convert code:

js:

self.filter = function() {     var s = $('#searchfield').val();     console.log(s.tolowercase().replace(/\b[a-z]/g,"kc"));     s = s.tolowercase().replace(/\b[a-z]/g, function(self) {       console.log(self.touppercase());       return self.touppercase();     });     $(".locationlist > li").each(function() {       console.log(this);       $(this).text().search(s) > -1 ? $(this).show() : $(this).hide();     });     for(var = 0; < self.placelist().length; i++) {       console.log(self.map);       self.placelist()[i].marker.setmap(self.placelist()[i].marker.title.search(s) > -1 ? map : null);     }   }; }; 

html:

<span class="glyphicon glyphicon-search" aria-hidden="true"></span> <input id="searchfield" data-bind="event: {keyup: filter}" type="text" placeholder='search name or city' value=""> <hr> <ul class="locationlist" data-bind="foreach: placelist">   <li>       ...  

to this:

javascript

self.filtertext = ko.observable(""); self.filteredlist = ko.computed(function(){   var filter = self.filtertext().tolowercase();   return // filter function. make sure return array of want!  }, this); 

you should use visible-binding on li-tag in repeater. straight forward hide items not meeting criteria. this:

<ul data-bind="foreach:placelist">   <li data-bind="text:$data, visible: filter"></li> </ul> 

Comments

Popular posts from this blog

sql - invalid in the select list because it is not contained in either an aggregate function -

Angularjs unit testing - ng-disabled not working when adding text to textarea -

How to start daemon on android by adb -