如何使用jquery uicombobox的远程源?
有一个combobox ,启用了自动完成function。 如何将JSON数据作为此combobox的源传递?
UPD。 我在这里找到了部分答案 – 它允许我使用远程数据源(原始var input = this.input = $( "" ).autocomplete({ source
替换为远程源)。但我不能选择值 – 看起来问题是使用以下代码(它允许从选择选项中选择值(我没有)。
select: function( event, ui ) { ui.item.option.selected = true; self._trigger( "selected", event, { item: ui.item.option }); },
如何解决?
这是演示。
这是工作示例 – http://jsfiddle.net/and7ey/TFerw/3/
在请求空term
时,远程端应该返回一些值(最常用) – 当用户按下combobox按钮时,它会发生。
从您在问题中添加的链接中获取的示例:
$( "#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 ); } });
我刚刚使用了下一个构造:1。在combobox.js中,我将示例中的代码放在https://jqueryui.com/autocomplete/#combobox上 ,并更改了_create和_createAutocomplete函数,如下所示:
_create: function() { this.wrapper = $( "" ) .addClass( "custom-combobox" ) .insertAfter( this.element ); var autocompleteSetup = this.options.autocompleteSetup; this.element.hide(); this._createAutocomplete( autocompleteSetup ); this._createShowAllButton(); } _createAutocomplete: function(setupObject) { ... this.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)...
-
从我正在创建组合的页面代码我调用创建代码如下:
var options = {autocompleteSetup:{delay:100,minLength:2,source:“ http:// your / data / hook / url ”}}; $(“#sububo”)。combobox(options);