【发布时间】:2016-03-24 03:16:11
【问题描述】:
我正在使用jQuery Autocomplete 小部件,并且受this question 的启发,为了防止在选择后关闭菜单,我想出了以下代码:
$(#input_field).autocomplete({
select : function(event, ui) {
// I also tried to run 'ui.item.data( "item.autocomplete" );' and it happens
// the same thing (keep reading for more information).
ui.item.option.selected = false;
},
...
});
有效:选择后菜单未关闭。但是,我收到以下错误(在 Firebug 控制台中):
TypeError: ui.item.option is undefined
即使使用option.selected = false,我也会得到TypeError: option is undefined,但它可以按预期工作。
我该如何解决?
【问题讨论】:
-
你能在jsfiddle.net上提供一个测试用例吗?
-
尝试在
select回调函数中添加console.log(ui)并检查您的控制台以查看在ui参数中传递的确切内容。 -
@Bogdan - 记录
ui对象,显示{ label="The label", value="The value" }。就是应该这样。 -
您使用的是最新的 jQuery 版本吗?根据Autocomplete Widget API Documentation,
select事件应该将ui.item传递给事件处理函数。
标签: javascript jquery jquery-ui autocomplete widget