Javascript 自定义easyAutoComplete
这是我现在用来获取远程Web服务数据的代码。现在我需要获取数据并删除重复的“城市名称”。此外,我还需要显示“数据不可用”或当Web服务中没有数据时的一些自定义方法。我有点卡住了。如果有人能告诉我如何实现这一点,那就太好了。您可以使用帮助程序Javascript 自定义easyAutoComplete,javascript,easyautocomplete,Javascript,Easyautocomplete,这是我现在用来获取远程Web服务数据的代码。现在我需要获取数据并删除重复的“城市名称”。此外,我还需要显示“数据不可用”或当Web服务中没有数据时的一些自定义方法。我有点卡住了。如果有人能告诉我如何实现这一点,那就太好了。您可以使用帮助程序功能来消除重复项。: var options = { url: function (phrase) { return "location/autoComplete?key=" + phrase; },
功能来消除重复项。
:
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 () {
}
}
}
};
功能移除副本(输入){
如果(!input){//Falsy input
返回输入;
}
var isArray=Array.isArray(输入)?[]:{};
var项目=[];
var输出={};
for(输入中的var键){
if(items.indexOf(输入[key])<0){
项目。推送(输入[键]);
如果(!isArray){
输出[键]=输入[键];
}
}
}
返回isArray?项:输出;
}
如果Array.isArray(输入),您可以显示自定义文本吗?(input.length==0):(Object.keys(input.length==0&&input.constructor==Object)
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;
}