我正在使用 easyautocomplete 。我从ajax请求中获取数据。然后我过滤它并创建一个easyauot完全支持的新对象。最后,我将其设置为选项数据,但它在控制台中显示以下错误:
物业' drenajs'在EasyAutocomplete选项API中不存在。
MeloGIS.getAllFeature=function(){
var url= 'url which gives me json data';
httpService.doAjax(url,'GET',null,null,function(response){
var json=response;
var dataJSON = JSON.parse(response);
var data = [];
var requestData = new Array();
for(var i in dataJSON.features) {
var item = dataJSON.features[i];
var attributes= item.attributes;
var geometry=item.geometry;
data.push({
"name" : attributes.name,
"collector" : attributes.collector
});
}
requestData.drenajs=[];
requestData.drenajs.push(data);
var parentStringify=JSON.stringify(requestData);
MeloGIS.autoComplete(requestData,"basics");
},
function(error){
return;
});
}
MeloGIS.autoComplete=function(jsonData,idInput){
var options = {
data : jsonData,
categories: [{
listLocation: "drenajs",
maxNumberOfElements: 4,
header: "--DRENAJLARIN SIYAHISI--"
}, {
listLocation: "pumps",
maxNumberOfElements: 4,
header: "--NASOSLARIN SIYAHISI--"
}],
getValue: function(element) {
return element.name;
},
template: {
type: "description",
fields: {
description: "collector"
}
},
list: {
maxNumberOfElements: 8,
match: {
enabled: true
},
sort: {
enabled: true
}
},
theme: "square"
};
$("#"+idInput).easyAutocomplete(jsonData);
}
但是当我设置这样的字符串时它工作正常。我做错了什么 ?
{
"drenajs": [
{"name": "drenaj1", "region": "Abseron rayonu"},
{"name": "Salam qaqa ", "region": "Nerimanov rayonu","adi":"ssss"},
{"name": "neynirsen", "region": "Nerimanov rayonu"},
{"name": "salamatcikodur", "region": "Nerimanov rayonu"},
{"name": "uc get", "region": "Nerimanov rayonu"},
{"name": "Rasul Rzayev", "region": "Nesimi rayonu"}
],
"pumps": [
{"name": "AAA", "region": "Nesimi rayonu"},
{"name": "Salam America", "region": "Xetai rayonu"},
{"name": "Test", "region": "Xirdalan rayonu"}
]
}
提前致谢。