horsey
horsey copied to clipboard
customize source
How to customize bindata to soucre from ajax
@dothanhit87
horsey(document.querySelector('.suggest'), {
source (data, done) {
$.ajax({
url : '',
type:'post',
dataType:'json',
data:{
search:data.input
},
success:function(items){
done(null, [{
list: items.filter(function (item) {
if(item.indexOf(data.input)!== -1) {
return true;
}
return false;
})
}])
}.bind(this)
});
},
getText:'name',
getValue:'id',
predictNextSearch(info) {
//console.log(info.selection); return selected item data
$("input").val(info.selection.id)
},
limit: 20
});