我使用 jquery-mobile 和 gmap-plugin 开发 PhoneGap 应用程序。我有一些代码和一些麻烦。
str = '';
db.transaction(function(t){
t.executeSql('SELECT name,address FROM table', [], function(t, res) {
for(var i=0; i<res.rows.length; i++) {
str += '<option selected="" value="'+res.rows.item(i).address+'">'+
res.rows.item(i).name + '</option>';
}
});
},null,function(){
$('#selectMenu').html(str);
$('#selectMenu').selectmenu("refresh");
$('#selectMenu').on('change', function () {
setMarks();
});
});
function setMarks (){
$('#map_canvas').gmap('clear', 'markers');
var el;
$("#selectMenu option:selected").each(function () {
el = $(this);
$('#map_canvas').gmap('search', { 'address': el.val() }, function(results, status) {
if ( status === 'OK' ) {
$('#map_canvas').gmap('addMarker', { 'position': results[0].geometry.location, 'bounds': true,
'html': "<h3>"+el.text()+"</h3><p>"+el.val()+"</p>"},
function(map, marker) {
$(marker).click(function() {
$('#map_canvas').gmap('openInfoWindow',{'content': $(this).attr('html')}, this);
return false;
});
});
}
});
});
}
在方法搜索对象的回调函数中, el是我所选元素集合中的最后一个,但我想查看每个对象。也许有人面临这样的问题。谢谢!