我必须从html表创建变量'stops'。 变量stop具有以下格式: (例子)
var stops = [
[ ' gussago ' , 45.593741,10.156832 , 1, ' this is gussago ' ]
[ ' Roncadelle ' , 45.530403,10.15101 , 2, ' this is Roncadelle ' ]
[ ' san zeno ' , 45.492691,10.217185 , 3, ' this is san zeno ' ]
.......
] ;
该变量用于使用谷歌地图
创建路径的标记 function setMarkers(map , stops ) {
for (var i = 0; i < stops.length ; i + + ) {
var beach = stops [i] ;
myLatLng var = new google.maps.LatLng (beach [1] , beach [2] ) ;
var marker = new google.maps.Marker ({
position: myLatLng ,
map : map ,
title : beach [0],
zIndex : beach [ 3]
html : beach [4]
});
必须从html表动态创建它 看起来像这样:
<table id="lista">
<thead> <tr> <th > ID </ th > <th > lat </ th > <th> Log </ th > <th > name </ th > <th > sentence </ th > </ tr>
</ thead >
<tbody >
<tr id="1"> <td class="name"> gussago </ td> <td class="lat"> 45.593741 </ td> <td class="log"> 10.156832 </ td > < td class = " id "> 1 </ td> <td class="frase"> this is gussago </ td > </ tr>
<tr id="2"> <td class="name"> Roncadelle </ td> <td class="lat"> 45.530403 </ td> <td class="log"> 10.15101 </ td > < td class = " id "> 2 </ td> <td class="frase"> this is Roncadelle </ td > </ tr>
...
<tr style="visibility:hidden;"> <td> < / td > <td> </ td> <td> < / td > <td> </ td> <td> < / td > </ tr>
</ tbody >
</ table>
我还必须排除'TR'隐藏
我尝试使用jquery创建一个数组,但它不起作用。这是代码:
$ ("#lista tbody ").each(function () {
$ (this).find('tr').each(function () {
index + + ;
arrayOfThisRow [index ] = [];
TableData var = $ (this). find ( ' td ' ) ;
if ( TableData.length > 0) {
tableData.each (function ( ) {
if ($ (this). hasClass ('name ' )) { var name = " ' " + $ (this). text () + " ' " ; arrayOfThisRow [ index]. push ( name );}
if ($ (this). hasClass ( ' lat ' )) { var lat = $ (this). text () ; arrayOfThisRow [ index]. push ( lat );}
if ($ (this). hasClass ( ' log ' )) { var log = $ (this) . text () ; arrayOfThisRow [ index]. push ( log) ;}
if ($ (this). hasClass ( ' id ' )) { var index = aindex ; arrayOfThisRow [ index]. push ( aindex );}
if ($ (this). hasClass ( ' sentence ' )) { var sentence = " ' " + $ (this). text () + " ' " ; arrayOfThisRow [ index]. push ( sentence );}
});
}
});
});
arrayOfThisRow.pop ();
arrayOfThisRow必须将变量传递给变量'stops'的函数
var stops = arrayOfThisRow
我希望我很清楚
答案 0 :(得分:0)
我通过在生成google标记的函数内构建数组来解决它,现在我遇到了另一种问题,而是新的请求。