因为这不是一个真正的问题,请忽略此问题,除非您想通过以下代码解决类似问题
我想在点击动态生成的表格行时在Google地图上绘制多边形。似乎数据已成功保存到该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}...]
将click事件绑定到表行的函数:
$('.tableLine').live('click', function (event){
var polygon = $(this).data("polygon");
if(polygon){
addPolygon(polygon);
}
});