Jquery 自动完成选择类型错误:ui.item 未定义 [英] Jquery Autocomplete Select TypeError: ui.item undefined
问题描述
我使用的是 jquery ui 1.10.3 和 jquery 2.0.3.我正在尝试使用自动完成功能在从自动完成的建议选项中选择一个选项时更改另一个文本框的文本.
I am using jquery ui 1.10.3 and jquery 2.0.3. I am trying to use the autocomplete function to change text of another text box on selecting an option from the suggested options from autocomplete.
以下是我的自动完成功能代码.我确实根据需要获得了结果,但是当我从中选择一个选项时,我收到了 TypeError: ui.item is undefined 错误.
Below is my code for the autocomplete function. I do get the results as needed but when I select an option from it, I get the TypeError: ui.item is undefined error.
<script language="javascript">
$(document).ready(function(){
$('#item_code').autocomplete({
source: "http://localhost/test/item/search_item",
minLength: 1,
select: function( event, ui ) {
$( "#item_description" ).val(ui.item.description );
return false;
}
}).data("ui-autocomplete" )._renderItemData = function( ul, item ) {
return $( "<li></li>" )
.data( "item.autocomplete", item )
.append( "<a>" + item.value + " - " + item.description + "</a>" )
.appendTo( ul );
};
});
</script>
我已经搜索了网络,但我发现我的头撞在桌子上.非常感谢任何帮助.
I have scoured the net but I have come to a point where I find banging my head on the table. Any help is greatly appreciated.
推荐答案
你应该只需要改变一个数据属性:
You should only need to change the one data property:
.data('item.autocomplete')
被弃用而支持
.data('ui-autocomplete-item')
从 jQuery UI 1.9 开始,从 jQuery UI 1.10 开始移除
As of jQuery UI 1.9 and removed as of jQuery UI 1.10
http://jqueryui.com/upgrade-guide/1.10/#removed-item-autocomplete-data-use-ui-autocomplete-item
这篇关于Jquery 自动完成选择类型错误:ui.item 未定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!