Jquery自动完成选择TypeError:ui.item undefined [英] Jquery Autocomplete Select TypeError: ui.item undefined

查看:115
本文介绍了Jquery自动完成选择TypeError:ui.item undefined的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用jQuery UI 1.10.3和jQuery 2.0.3。
我试图使用自动完成功能来改变另一个文本框的文本,从自动完成的建议选项中选择一个选项。



以下是我的代码自动完成功能。我根据需要得到了结果,但是当我从中选择一个选项时,出现 TypeError:ui.item未定义错误。

 < 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; $ ($ lt; / li>)

})。data $ b .data(item.autocomplete,item)
.append(< a> + item.value + - + item.description +< / a>)
.appendTo(ul);
};
});
< / script>

我已经在网上搜寻过了,但是我已经到了一个让我的头撞在桌子上的地步。
任何帮助都非常感谢。

解决方案

您应该只需要更改一个数据属性:

  .data('item.autocomplete')

已被弃用,以支持

  .data('ui-autocomplete-item')

截至jQuery UI 1.9并从jQuery UI 1.10中移除

http:// jqueryui.com/upgrade-guide/1.10/#re​​moved-item-autocomplete-data-use-ui-autocomplete-item


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.

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')

was deprecated in favour of

.data('ui-autocomplete-item')

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自动完成选择TypeError:ui.item undefined的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆