嘿所有我有以下代碼:jQuery的陣列對象獲取值
var items = [];
$(xml).find("Placemark").each(function() {
var tmp_latLng = $(this).find("coordinates").text();
tmp_latLng = tmp_latLng.split(",");
items.push({
name: $(this).find("name").text(),
snippet: $(this).find("Snippet").text(),
description: $(this).find("description").text(),
lat: tmp_latLng[0],
lng: tmp_latLng[1],
distance: $(this).find("distance").text()
});
});
var markerNodes = items;
if (markerNodes.length > 0) {
howManyMarkers = markerNodes.length;
for (var i = 0; i < markerNodes.length; i++) {
console.log(markerNodes[i].Snippet);
var name = markerNodes[i].getAttribute("Snippet");
var address = markerNodes[i].getAttribute("Snippet");
var description = markerNodes[i].getAttribute("description");
var distance = parseFloat(markerNodes[i].getAttribute("distance"));
var latlng = new google.maps.LatLng(parseFloat(markerNodes[i].getAttribute("lat")), parseFloat(markerNodes[i].getAttribute("lng")));
createOption(name, distance, i);
createMarker(latlng, name, address);
bounds.extend(latlng);
}
map.fitBounds(bounds);
} else {
alert('Sorry, there are no stores that close to your location. Try expanding your search radius.');
}
該錯誤是在的console.log(markerNodes [I]是.snippet);。該錯誤是未捕獲的類型錯誤:未定義不是函數
另外,markerNodes [I] .getAttribute(「片段」)具有遺漏的類型錯誤的誤差:未定義不是函數
我會錯過什麼?
和第二個未定義的問題? – Phil 2014-11-04 20:09:46
完全相同的原因。 – 2014-11-04 20:10:32
'markerNodes [i] .getAttribute(「Snippet」)與片段的拼寫有什麼關係?什麼是'getAttribute()'? – Phil 2014-11-04 20:11:45