var options = {
url: function (phrase) {
return "location/autoComplete?key=" + phrase;
},
getValue: "cityName",
template: {
type: "custom",
method: function (value, item) {
return value + ", " + item.stateName;
}
},
list: {
onClickEvent: function () {
var selectedLongitude = $("#autoCompleteSearch").getSelectedItemData().longitude;
var selectedLatitude = $("#autoCompleteSearch").getSelectedItemData().latitude;
userPos = {
lat: Number(selectedLatitude),
lng: Number(selectedLongitude)
};
map.setCenter(userPos);
map.setZoom(17)
},
showAnimation: {
type: "fade", //normal|slide|fade
time: 400,
callback: function () {
}
},
hideAnimation: {
type: "slide", //normal|slide|fade
time: 400,
callback: function () {
}
}
}
};这是我现在用来获取远程the服务数据的代码。现在我需要获取数据并删除重复的“城市名称”。此外,我需要显示“数据不可用”或一些自定义的方法,当没有来自网络服务的数据。我有点卡住了。如果有人能告诉我如何做到这一点,那就太好了。
发布于 2017-05-12 18:31:55
您可以使用帮助器function消除重复项
function removeDuplicates(input) {
if (!input) { //Falsy input
return input;
}
var isArray = Array.isArray(input) ? [] : {};
var items = [];
var output = {};
for (var key in input) {
if (items.indexOf(input[key]) < 0) {
items.push(input[key]);
if (!isArray) {
output[key] = input[key];
}
}
}
return isArray ? items : output;
}如果为Array.isArray(input) ? (input.length === 0) : (Object.keys(input).length === 0 && input.constructor === Object),则可以显示自定义文本。
https://stackoverflow.com/questions/43935040
复制相似问题