使用keyup keydown从自动填充列表中选择选项时,textbox显示值。但是从鼠标中选择它可以正常工作。 JsFiddle - http://jsfiddle.net/0c21r1pe/1
$("#promoteActionTextBox").autocomplete({
source: actionNames,
minLength: 0,
select: function (event, ui) {
event.preventDefault();
$(this).val(ui.item.label);
$('#promoteActionError').hide();
$(this).attr('actionId', ui.item.value);
},
change: function (event, ui) {
if (!ui.item) {
$(this).val('');
}
else {
$('#promoteActionError').hide();
$(this).val(ui.item.label);
$(this).attr('actionId', ui.item.value);
}
}
}).focus(function (event, ui) {
event.preventDefault();
$('#promoteActionTextBox').autocomplete("search");
this.value = ui.item.label;
});
答案 0 :(得分:4)
将对象属性名称从value
更改为其他内容并且可以正常工作
<强>更新强>
怎么样?我添加了一个代码,用于删除导致该效果的事件。
create:function(){
$('.ui-autocomplete').unbind('menufocus');
}
答案 1 :(得分:0)
# This is just a random example that I generated myself.
locations = (
{
"location_id": 1234,
"location_name": "Spain",
},
{
"location_id": 5678,
"location_name": "France",
}
)
areas = [] # Initialize a list if you haven't.
for location in locations:
areas.append(location["location_name"])