bootstrap-suggest
bootstrap-suggest copied to clipboard
map: not working with ajax
Hi, First of all, thank you for this awesome plugin. when I am using your plugin with prefetched data then it is working fine. Showing all the result
`$('.short_code').suggest('#', {
data: text_shortcuts_array,
map: function(text_shortcut) {
return {
value: text_shortcut.text,
text: '<strong>'+text_shortcut.value+'</strong><br>'
}
},
})`
But when I am using ajax for data things are not working fine for me. I don't know where I am doing wrong
$('.short_code').suggest('#', {
data: function(q, provide) {
$.getJSON("/someurl", { q: q }, function(data) {
text_shortcuts = data;
var text_shortcuts_array = [];
$.each(text_shortcuts, function (key, value) {
text_shortcuts_array.push({
value: value['Textshortcut']['shortcut'],
text: value['Textshortcut']['text']
});
})
<!-- I am getting value here -->
provide.call(text_shortcuts_array);
});
},
map: function(text_shortcut) {
return {
value: text_shortcut.text,
text: '<strong>'+text_shortcut.value+'</strong><br>'
}
},
})`
```
"Add delay search while typing" is not working. When I integrate as per the instruction, dropdown box is not showing
Also, there is another issue. If we do not use "Delay" then "map" function is not loading getting the Latest records from ajax
For what it's worth, I too had trouble with the provide.call()
method. But I was able to get it to work by returning a jqXHR promise. So if you need to do some post-processing of the ajax response, you might try wrapping the $.getJSON()
call in a JQuery promise, then resolving the promise after post-processing the ajax data.