How to use remote source with jquery ui combobox?

前端 未结 3 1880
情话喂你
情话喂你 2020-12-19 16:58

There is combobox with autocomplete enabled. How to pass JSON data as source for this combobox?

Upd. I\'ve found partial answer here - it allows me

相关标签:
3条回答
  • 2020-12-19 17:41

    Here is the working example - http://jsfiddle.net/and7ey/TFerw/3/

    Remote end should return some values (most popular) in case when empty term is requested - it happens when user presses combobox button.

    0 讨论(0)
  • 2020-12-19 17:45

    Example taken from the link you added in your question :

            $( "#birds" ).autocomplete({
                source: "search.php", // remote site
                minLength: 2,
                select: function( event, ui ) {
                    log( ui.item ?
                        "Selected: " + ui.item.value + " aka " + ui.item.id :
                        "Nothing selected, input was " + this.value );
                }
            });
    
    0 讨论(0)
  • 2020-12-19 17:54

    I just used next construction: 1. In combobox.js I put code from example that appears on https://jqueryui.com/autocomplete/#combobox and had changed _create & _createAutocomplete functions as follows:

     _create: function() {
            this.wrapper = $( "<span>" )
                .addClass( "custom-combobox" )
                .insertAfter( this.element );
    
            var autocompleteSetup = this.options.autocompleteSetup;
            this.element.hide();
            this._createAutocomplete( autocompleteSetup );
            this._createShowAllButton();
        }
    
        _createAutocomplete: function(setupObject) {
    ...
    this.input = $( "<input>" )
                .appendTo( this.wrapper )
                .val( value )
                .attr( "title", "" )
                .addClass( "custom-combobox-input ui-widget ui-widget-content ui-state-default ui-corner-left" )
                .autocomplete(setupObject)...
    
    1. From page code where I'm creating the combo I am calling the create code as follows:

      var options = { autocompleteSetup : { delay: 100, minLength: 2, source: "http://your/data/hook/url" } }; $( "#subzero" ).combobox(options);

    0 讨论(0)
提交回复
热议问题