Jquery: Possible to dynamically change source of Autocomplete widget?

后端 未结 1 1230
暖寄归人
暖寄归人 2020-12-05 23:01

Greetings,

I am using the official Autocomplete jquery widget and am having troubles dynamically changing a variable (selectType) I\'m passing via the query string.

相关标签:
1条回答
  • 2020-12-05 23:15

    Try actually changing the source option of the autocomplete on the change event.

    $(function () {
        var select = $( "#selectType" ),
            options = select.find( "option" ),
            address = $( "#address" );
    
        var selectType = options.filter( ":selected" ).attr( "value" );
        address.autocomplete({
            source: "ajaxSearchForClientAddress.php?selectType=" + selectType,
            minLength: 3
        });
    
        select.change(function () {
            selectType = options.filter( ":selected" ).attr( "value" );
            address.autocomplete( "option", "source", "ajaxSearchForClientAddress.php?selectType=" + selectType );
        });
    });
    
    0 讨论(0)
提交回复
热议问题