javascript - Jquery 自动完成不附加

标签 javascript jquery jquery-ui jquery-plugins jquery-autocomplete

这里是 Jquery 新手。 我的 jquery 附加似乎不起作用。 非常感谢任何帮助。

我使用的是 jquery 版本 1.8.3 和 UI 1.9.2。

下面是我的代码。

$('.tinputer').autocomplete({
        source: "http://localhost/myapp/items/search_item",
        minLength: 1,
        select: function(event, ui) {
            var $itemrow = $(this).closest('tr');
            $itemrow.find('#item_description').val(ui.item.description);
            $itemrow.find('#unit_price').val(ui.item.price);
            $itemrow.find('#qty').focus();
            verify_item(ui.item.value);
        }
    }).data("autocomplete" )._renderItem = function( ul, item ) {
        return $( "<li></li>" )
        .data( "item.autocomplete", item )
        .append( "<a>" +  item.value + item.description + "</a>" )
        .appendTo( ul );
    };

fiddle - http://jsfiddle.net/Yw2Y7/1/ 尝试在第二行的项目框中键入内容。第一行有效。

结果被填充,我得到下拉列表,但只显示值。 item.description 未附加,或者附加部分似乎被完全忽略。

非常感谢您的帮助。

最佳答案

$('.tinputer').autocomplete({
source: projects,
minLength: 1,
select: function (event, ui) {
    var $itemrow = $(this).closest('tr');
    $itemrow.find('#item_description').val(ui.item.description);
    $itemrow.find('#unit_price').val(ui.item.price);
    $itemrow.find('#qty').focus();
    verify_item(ui.item.value);
}
}).

each(function(){               //This is the line added.


$(this).data("autocomplete")._renderItem = function (ul, item) {
return $("<li></li>")
    .data("item.autocomplete", item)
    .append("<a>" + item.value + " - " + item.description + "</a>")
    .appendTo(ul);
} }           
 );

演示 http://jsfiddle.net/skhan/Yw2Y7/3/

关于javascript - Jquery 自动完成不附加,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22292380/

相关文章:

javascript - 显示或隐藏元素会影响下方 div 的位置

javascript - jQuery 数据表 : Individual column searching not working

jQuery autocomplete - 获取自动完成输入字段的 id

javascript - HTML 输入字段可自动检索分钟、小时和天的粒度

javascript - 如何在书签中嵌套 jquery 和 jquery-ui 的 cdn 加载?

jquery - 如何在加载选项卡内容时显示加载图像?

javascript - 在多个绑定(bind)的 KnockoutJs 订阅函数中完成相同的任务

javascript - 如何让汽车沿着路径行驶

jquery - 使用 jQuery 将行添加到表时如何应用淡入效果

jQuery Ui datepicker 仅构建容器