search box and markers doesn't work as i need

62 views
Skip to first unread message

Eleni Minadaki

unread,
Jul 31, 2017, 1:32:45 PM7/31/17
to KnockoutJS
hi guys, trying to create a google map, using knockout, i have stuck in 2 points.
1_i need search box have the ability the user to type in and the list decrease the titles while user types.
2_when tittles from the list decrease markers should be decreased also, but have no idea how to make that.
an example about how my search box and markers works is this:https://codepen.io/dmoojunk/pen/KzXGKq
any help appreciated!

noirabys

unread,
Aug 3, 2017, 7:13:50 AM8/3/17
to KnockoutJS
   self.filteredPlaces = ko.computed(function(){
       var reply = [];
       ko.utils.arrayForEach(self.places(),function(p){
          if(p.name.toLowerCase().indexOf(self.query().toLowerCase()) > 0) {
             reply.push(p);
          }
       });
       return reply;
    });

  use filteredPlaces in your ul:
    <ul data-bind="foreach: filteredPlaces">
      <li data-bind="text: $data.name"></li>
    </ul>
Reply all
Reply to author
Forward
0 new messages