0
index page
에 마커가 있으며 루프에서 청취자를 등록합니다. 그 마커 중 하나를 클릭하면 next page
으로 이동합니다. anchor button
은 마커가 작업을 시작했는지 알아야합니다. 나는 현명한 다음과 같은 시나리오 단계를 겪고 :Google지도 v3의 루프에있는 마커 수신기
- 클릭 마커 1
//outputs a correct id 1 in console
- 이
//outputs a correct id 1 in console on clicking anchor
- 인덱스 페이지로 돌아 와서 마커 2
//outputs a correct id 2 in console
- 클릭 다음 페이지로 저를 이동합니다 다음 페이지로 나 이동합니다
//outputs both ids 1 and 2 in console on clicking anchor
마지막 단계는 어디에 문제가 있습니까? id 2
입니다. 사실 세 번째로이 과정을 반복하면이 경우에는 id 3
만 필요한 반면 1, 2, 3의 모든 ID를 얻습니다.
내 코드 : 당신이 markerOtherLocations을 클릭하면
$.each(otherLocations, function(index, value){
var markerOtherLocations = new MarkerWithLabel({
position: new google.maps.LatLng(value.latitude, value.longitude),
map: map,
title: value.name+" "+value.distance,
icon: iconImage,
labelContent: value.name+" "+value.distance,
labelAnchor: new google.maps.Point(50, 0),
labelClass: "labels", // the CSS class for the label
labelStyle: {opacity: 0.60}
});
google.maps.event.addListener(markerOtherLocations, 'click', function() {
$.mobile.changePage("#detail-page", { transition: "flip"});
console.log(value.localurl);//Outputs correct url
$("#ref").on("click", function(){ //The problem is in this anchor click
console.log(value.localurl);//Outputs the current as well as all the previous urls
});
});
});
예, 당신이 일을 제안한 방법. 이제 클릭 한 최신 마커의'handle'을 받았습니다. 그러나'each 루프 '안에 있었기 때문에 나는 여러 번 같은'handle'을 얻고있었습니다. 루프 외부에 놓았으니 지금은 완벽합니다. 그러나 다시 캐치는,'새로 고침 할 때 전체 스크립트가 다시 실행되는 결과로 '인덱스 페이지'에 새로 고침 기능이 있기 때문입니다. 이것 때문에 나는 올바른'handle'을 여러 번 다시 얻는다. 하지만 그건 중요하지 않습니다. 적어도 나는 정확한 것을 얻고있다. 많은 감사 ... ...-) – SASM