[英]JQuery-UI autocomplete search() not displaying DropDownList
Given the documentation for the search
method for the Autocomplete Widget, I would expect a button that calls this method would display a box containing a list of available selections. 给定自动完成小部件的search
方法的文档 ,我希望有一个调用该方法的按钮将显示一个包含可用选择列表的框。 Nothing happens. 什么都没发生。
I have the following code that creates the autocomplete widget on a text box: 我有以下代码在文本框中创建自动完成小部件:
$("#StateListCoolBox").autocomplete({
source: StateListCoolBoxTags,
focus: function( event, ui ) {
$("#StateListCoolBox").val(ui.item.label);
return false;
},
select: function( event, ui ) {
$("#StateListCoolBox").val(ui.item.label);
$("#StateListCoolBox-id").val(ui.item.value);
return false;
}
});
It works fine. 工作正常。
I have the following code attached to the button I want to display the list. 我在要显示列表的按钮上附加了以下代码。 It gets called but nothing happens: 它被调用但是什么都没有发生:
function StateListCoolBox_dropDownClick() {
$("#StateListCoolBox").autocomplete("search", "" );
};
I have tested this with text in the corresponding textbox and with the textbox blank. 我已经用相应的文本框中的文本和空白的文本框对此进行了测试。
How do I get a button to behave like the button on a DropDown Combo, so that when clicked, the list of available selections is displayed? 如何获得与DropDown Combo上的按钮类似的按钮,以便单击时显示可用选择的列表?
If you look at the "View Source" for this: http://jqueryui.com/autocomplete/#combobox 如果您在此查看“查看源代码”: http : //jqueryui.com/autocomplete/#combobox
You will see: 你会看见:
_createShowAllButton: function() {
var input = this.input,
wasOpen = false;
$( "<a>" )
.attr( "tabIndex", -1 )
.attr( "title", "Show All Items" )
.tooltip()
.appendTo( this.wrapper )
.button({
icons: {
primary: "ui-icon-triangle-1-s"
},
text: false
})
.removeClass( "ui-corner-all" )
.addClass( "custom-combobox-toggle ui-corner-right" )
.on( "mousedown", function() {
wasOpen = input.autocomplete( "widget" ).is( ":visible" );
})
.on( "click", function() {
input.trigger( "focus" );
// Close if already visible
if ( wasOpen ) {
return;
}
// Pass empty string as value to search for, displaying all results
input.autocomplete( "search", "" );
});
}
So this shows all the results by triggering focus event on the text field. 因此,这通过触发文本字段上的焦点事件来显示所有结果。
How do I get a button to behave like the button on a DropDown Combo, so that when clicked, the list of available selections is displayed? 如何获得与DropDown Combo上的按钮类似的按钮,以便单击时显示可用选择的列表?
I think this fits what you wanted to accomplish. 我认为这符合您想要实现的目标。 So Try the following with minLength: 0
: 因此,请使用minLength: 0
尝试以下操作minLength: 0
:
function StateListCoolBox_dropDownClick() {
$("#StateListCoolBox").trigger("focus").autocomplete( "search", "" );
};
That said, there should be nothing wrong with your method: 也就是说,您的方法应该没有问题:
Triggers a
search
event and invokes the data source if the event is not canceled. 触发search
事件并在未取消事件的情况下调用数据源。 Can be used by a selectbox-like button to open the suggestions when clicked. 单击时可被类似选择框的按钮用来打开建议。 When invoked with no parameters, the current input's value is used. 不带参数调用时,将使用当前输入的值。 Can be called with an empty string andminLength: 0
to display all items. 可以使用空字符串和minLength: 0
调用以显示所有项目。
Your current code is simply missing: minLength: 0
. 您当前的代码只是丢失了: minLength: 0
。 Try both if you like. 如果您愿意,请尝试两者。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.