Created
September 8, 2017 11:39
-
-
Save william251082/753b716efea9ad3d6a8406c50779e76b to your computer and use it in GitHub Desktop.
Search Filter KO
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var locations= //js objects [{name: 'Park Ave Penthouse']; | |
| var Location = function(data) { | |
| this.name = data.name; | |
| this.visible = ko.observable(true) | |
| }; | |
| var ViewModel = function(){ | |
| var self = this; | |
| this.myLocations = ko.observableArray(); | |
| locations.forEach(function(location) { | |
| self.myLocations.push(new Location(location)); | |
| }); | |
| this.markers = ko.observableArray(locations); | |
| this.address = ko.observable(""); | |
| // http://knockoutjs.com/documentation/click-binding.html#note-1-passing-a-current-item-as-a-parameter-to-your-handler-function | |
| this.doSomething = function(clickedLocation) { | |
| //console.log("click"); | |
| populateInfoWindow(clickedLocation.marker); | |
| console.log(clickedLocation); | |
| // use location.marker to open the marker's info window | |
| }; | |
| this.search = function(value) { | |
| // remove all the current locations, which removes them from the view | |
| if (value) { | |
| //viewModel.myLocations.removeAll(); | |
| //this.mylocations().forEach | |
| for(var x in locations) { | |
| if(locations[x].name.toLowerCase().indexOf(value.toLowerCase()) >= 0) { | |
| self.myLocations()[x].visible(true); | |
| } else { | |
| self.myLocations()[x].visible(false); | |
| } | |
| } | |
| } | |
| } | |
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <p><h1>Locations</h1></p> | |
| <form> | |
| <input placeholder="Search.." type="search" data-bind="textInput: address"> | |
| </form> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment