devbridge / jQuery-Autocomplete

Ajax Autocomplete for jQuery allows you to easily create autocomplete/autosuggest boxes for text input fields
https://www.devbridge.com/sourcery/components/jquery-autocomplete/
Other
3.57k stars 1.67k forks source link

Possible to pass extra dynamic data? #804

Closed UnexpectedMaker closed 3 years ago

UnexpectedMaker commented 3 years ago

Hi, I love this implementation of autocomplete, but I'm wanting to also pass in a dynamic variable (from a dropdown list) so the service url know's where I am wanting to pull the data from.

I can't seem to work out how to do this. Is is possible?

Thanks :)

tkirda commented 3 years ago

You can call setOptions to set additional params when the dropdown value changes:

$('#autocomplete').autocomplete('setOptions', { params: { customValue: '...' } });

In this case, params will be used as query string parameters.

netmou commented 1 year ago

How do you handle later-bound elements ,like :

$(document).on('click', '.add_line', function(){
        var tr=$(this).closest("tr");
        var clone = tr.clone();
        clone.insertAfter(tr);
        // 给新加行的绑定自动不全
        clone.find('[name="title[]"]').autocomplete({
            serviceUrl: "{:url('admin/caigou/caixunjia_ing_json')}",
            noSuggestionNotice: "未匹配到数据,换个关键字试试。",
            minChars:0,
            onSelect: function (suggestion) {
                var tr = $(this).closest("tr");
                tr.find("input[name='xinghao[]']").val(suggestion.xinghao);
                tr.find("input[name='guige[]']").val(suggestion.guige);
                tr.find("input[name='jia[]']").val(suggestion.jia);
                comput.apply(this);
            }
        })