1
私はデフォルトでいくつかのマーカーを表示するGoogleマップを作成しています。ユーザーが特定の場所に入ると、その場所のみのマーカーが残っていなければならず、残りの作業が消えなければなりません。マーカーとマップが働いている間に、フィルタ機能はworking.My JSコードではありません以下のとおりである。ノックアウト - Google maps marker filter
function inintMap()
{
var map;
var bounds = new google.maps.LatLngBounds();
var mapOptions = {
mapTypeId : 'roadmap'
};
map = new google.maps.Map(document.getElementById('map'),mapOptions);
map.setTilt(45);
var locations = [
['London Eye, London', 51.503454,-0.119562],
['Palace of Westminster, London', 51.499633,-0.124755]
];
for (i=0; i < locations.length; i++)
{ var position = new google.maps.LatLng(locations [i][1],locations [i][2]);
bounds.extend (position);
marker = new google.maps.Marker({
position : position,
map : map,
title : locations [i][0]
});
map.fitBounds(bounds);
}
var vm = {
locations: ko.observableArray(locations)
};
vm.query = ko.observable('')
vm.search = function(value){
vm.locations.removeAll()
for(var x in locations) {
if(locations[x].name.toLowerCase().indexOf(value.toLowerCase()) >= 0) {
viewModel.locations.push(locations[x]);
}
}
}
vm.query.subscribe(vm.search);
ko.applyBindings(vm);
}
http://stackoverflow.com/questions/500504/why-is-using-for-in-with-array-iteration-a-bad-idea –
コンソールにエラーはありますか?どのように動作していないのですか? –