您好,我正在尝试获取每个循环的位置。Yahoo placemaker 用于从数组的文本变量中获取位置。在每个循环中,我将位置发送到外部函数,但我没有得到值。有谁知道做错了什么?谢谢!
function replace_undefined(array, text_array) {
console.log(text_array);
for (i = 0, l = text_array.length; i < l; i++) {
var text = array[i].text;
Placemaker.getPlaces(text, function (o) {
console.log(o);
if ($.isArray(o.match)) {
if (o.match[0].place.name == "Europe" || o.match[0].place.name == "United States") {
var location = o.match[1].place.name;
getLocation(location);
}
if ($.isArray(o.match)) {
if (o.match[0].place.name !== "Europe") {
var location = o.match[0].place.name;
getLocation(location);
}
}
}
if (!$.isArray(o.match) && o.error == "no locations found") {
var location = "";
getLocation(location);
}
if (!$.isArray(o.match) && o.error !== "no locations found") {
var location = o.match.place.name;
getLocation(location);
}
});
}
function getLocation(n) {
return function () {
console.log('Location: ' + n);
};
}
}