Jquery Autocomplete Error : Cannot Read Property 'label' Of Undefined
With reference to AutoComplete in Bot Framework , I had implemented GET method of search URL. Below is my code:
Solution 1:
I am finally able to fix my issue with below solution.
Note: JQuery Autocomplete "response" method takes array as data type.
Answer : 1) when we are passing entire API array results to "response" method, results must have "label" keyword with proper data.
sample code while passing entire API results:
response(data.value.map(x => x["@search.text"]));
2) when we don't have "label" keyword in API response, we have to format response as per requirements and create a new array of data that we want to display as auto suggest and pass to "response" method.
Below is code for same:
var autoSuggestDataToDisplay= [];
var inputValue = request.term;
for (i = 0; i < data.value.length; i++) {
var allquestions = data.value[i].questions;
if (allquestions.length > 0) {
for (j = 0; j < allquestions.length; j++)
if (allquestions[j].toLowerCase().indexOf(inputValue.toLowerCase()) != -1) {
result = result + "," + allquestions[j];
if (autoSuggestDataToDisplay.indexOf(allquestions[j].toLowerCase()) === -1) {
autoSuggestDataToDisplay.push(allquestions[j].toLowerCase());
}
}
}
}
if (result != null) { response(autoSuggestDataToDisplay); }
else { alert("no data"); }
As i dont have "label" in API response, I followed #2 approach and solved it.
Post a Comment for "Jquery Autocomplete Error : Cannot Read Property 'label' Of Undefined"