我有以下问题代码进一步向下。当我这样做时
city[i] = response[i].name;
我可以打印出我拥有的每个城市的每个名字。但是现在我想要一个多维数组,因为我还想保存以下代码
L.marker([response[i].lat, response[i].lon]).bindPopup(response[i].name);
而且我认为我可以将它保存在一个多维数组中,所以当我们有一个例子
city[1]["CityName"] = "New York"
city[1]["Locations"] = L.marker([location]).bindPopup(name);
所以,现在当我打电话时,city[1]['Locations']
我得到了 L.Marker,对吧?
这是我的代码
function init()
{
region = 'all';
var url = "http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png",
attribution = "(c) OSM contributors, ODBL";
var minimal = L.tileLayer(url, {styleID: 22677, attribution: attribution});
$.ajax
({
type: 'GET',
url: 'webservice.php',
data: {region: region},
success: function(response, textStatus, XMLHttpRequest)
{
var city = new Array();
var lygStr = '';
for(var i = 0; i < response.length; i++)
{
//alert(response[i].lat + " | " + response[i].lon + " | " + response[i].name);
alert(response[i].name);
city[i]["CityName"] = response[i].name;
//L.marker([response[i].lat, response[i].lon]).bindPopup(response[i].name);
if(i + 1 == response.length)
{
lygStr += city[i]["CityName"];
}
else
{
lygStr += city[i]["CityName"] + ", ";
}
}
alert("Test" + lygStr);
var cities = L.layerGroup([lygStr]);
map = L.map("map1",
{
center: new L.Latlng(resposne[1].lat, response[0].lon),
zoom: 10,
layers: [minimal, cities]
});
}
});
}