infoWindow
divの編集、共有または削除をクリックしたときに呼び出されるjQuery関数の実行に問題があります。Infowindow Button jQueryイベント
var markers = [];
for(i=0; i<array.length; ++i) {
var marker = new google.maps.Marker({
position: {lat: parseFloat(array[i]['latitude']), lng: parseFloat(array[i]['longitude'])},
map: map
});
var id = array[i]['id'];
var edit = 'edit', share = 'share', del = 'delete';
var cString = '<div style="margin: auto; text-align: center; font-family: Tahoma, Geneva, sans-serif;"><strong>Location Name: </strong>' + array[i]['title']
+ '<br><strong>Location Description: </strong>' + array[i]['description']
+ '<br><br><br><div class="btn-group"><button type="button" class="btn btn-primary '+edit+'" id="' + id + '">Edit</button><button type="button" class="btn btn-primary '+share+'" id="' + id + '">Share</button><button type="button" class="btn btn-primary '+del+'" id="' + id + '">Delete</button></div>';
contentString.push(cString);
google.maps.event.addListener(marker, 'click', (function(marker, i) {
return function() {
infoWindow.setContent(contentString[i]);
infoWindow.open(map, marker);
}
})(marker, i));
// this is the function
$('button').click(function() {
console.log('clicked');
});
markers.push(marker);
}
はinfoWindow
に割り当てられたボタンのクリックは表示されませんが、等サインアウト、ビュー・プロファイルのような他のボタンに
アレイは、構造を有するたJSONアレイであるん
を[
{
id:"1"
description:"I am Loving It! ↵McArabia Combo Meal: 520 Rs/-"
latitude:"25.28919345"
longitude:"67.11113134"
title:"McDonalds"
type:"favourite"
},//....
//......
]
どうすればこの問題を解決できますか?
これらの動的にボタンが追加されます。イベントをボタンにバインドするには、jquery [.on()](http://api.jquery.com/on/)を使用します。 forループ内にイベントバインディングを配置する必要はありません。 – anu