1
我正在創建一個默認顯示幾個標記的谷歌地圖。當用戶進入特定位置時,只有該位置的標記必須保留,其餘的作品必須消失。雖然標記和映射工作,過濾器的功能是不是working.My JS代碼如下:淘汰賽 - Google地圖標記過濾器
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 –
在控制檯中是否有任何錯誤?它以什麼方式不起作用? –