我有一堆标记index page
,我在其中循环创建和注册听众。我单击其中一个标记,它会将我带到next page
需要anchor button
知道哪个标记启动操作的位置。我逐步有以下情况:
- 单击标记 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 1、2 和 3,而id 3
在这种情况下我只想要 id。
我的代码:
$.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
});
});
});