由于这不是一个真正的问题,请忽略此问题,除非您想使用以下代码解决类似问题
当单击动态生成的表格线时,我想在谷歌地图上绘制一个多边形。似乎数据已成功保存到该 dom,但无法在 $.each() 函数之外再次读取。
$.getJSON(url, function(json) {
$.each(json, function(index) {
var id = "tableLine_"+index;
tbody.append(
'<tr id='+id+' class="tableLine">'+
'<td>'+ this.status+ '</td>'+
'<td>'+ this.name+'</td>'+
'<td>'+ this.city+'</td>'+
'<td>'+ this.street+'</td>'+
'<td>'+ this.language+'</td>'+
'<td>'+ this.distance+'</td>'+
'</tr>'
);
//save data to the specific 'tr'
$("tr#"+id).data("polygon",this.polygon);
//this proved that the data was saved
alert($("tr#"+id).data("polygon"));
});
$("table").tablesorter({
sortLocaleCompare: true,
widgets: ['zebra']
}).tablesorterPager({
container: $(".pager"),
size: 15
});
});
多边形:
"polygon":[{"x":48.235752,"y":11.685345},{"x":48.21908,"y":11.686883}...]
将点击事件绑定到表格行的函数:
$('.tableLine').live('click', function (event){
var polygon = $(this).data("polygon");
if(polygon){
addPolygon(polygon);
}
});