2013-12-11 135 views
1

我有一個列表與他們裏面的對象列表,我需要遍歷所有列表中的每個對象。這是我所嘗試過的,但並不按我打算的方式工作。迭代對象列表

dict_values([[<mapvis.store.Node object at 0x14fd370>, <mapvis.store.Node object at 0x13c4270>], [<mapvis.store.Node object at 0x14fd930>, <mapvis.store.Node object at 0x14fd490>], ]) 

js函數

​​

多數民衆贊成生成的HTML。我希望它有lat_lng的實際值intstead [0] .lng

function displayRoads(map) { 
    var points = new google.maps.MVCArray(); 
    points.push(new google.maps.LatLng(lat_lng[0].lat, lat_lng[0].lng)); 
    points.push(new google.maps.LatLng(lat_lng[1].lat, lat_lng[1].lng)); 
    createPolyline(map, points); 
... 
.. 
... 
} 
+1

問題是什麼? – user2357112

+0

在問題中增加了更多信息 – Pierre

回答

2

使用{{ variable }}語法。

function displayRoads(map) { 
    {% for create_lat_lng in get_lat_lng %} 
     {% for lat_lng in create_lat_lng %} 
     var points = new google.maps.MVCArray(); 
     points.push(new google.maps.LatLng({{ lat_lng.0.lat }}, {{ lat_lng.0.lng }})); 
     points.push(new google.maps.LatLng({{ lat_lng.1.lat }}, {{ lat_lng.1.lng }})); 
     createPolyline(map, points); 
     {% endfor %} 
    {% endfor %} 
} 

只是爲了澄清,{{ lat_lng.0.lat }}lat_lng變量是指接入指數爲零,然後拿到字典鍵lat的價值。所以上面的代碼假定lat_lng是一個包含字典的數組/元組。

+0

它給了我沒有像這樣的值points.push(new google.maps.LatLng(,)); points.push(new google.maps.LatLng(,)); – Pierre

+0

'lat_lng'是數組還是字典?通過你的代碼,我認爲它是一個數組。如果是字典,則可以嘗試使用「{{lat_lng.lat}}」和「{{lat_lng.lng}}」。我需要知道'lat_lng'變量的實際結構來給出一個精確的答案。 – Rafa