horsey icon indicating copy to clipboard operation
horsey copied to clipboard

customize source

Open dothanhit87 opened this issue 7 years ago • 1 comments

How to customize bindata to soucre from ajax

dothanhit87 avatar Jun 13 '17 10:06 dothanhit87

@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
    });

WG-Com avatar Dec 01 '17 03:12 WG-Com