문제

Jquery newbie here. My jquery append does not seem to be working. Any help is greatly appreciated.

I am using jquery version 1.8.3 and UI 1.9.2.

Below is my code.

$('.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/ Try typing in the item box on the second row. The first row works.

The results get populated, and I get the drop down, but only value is shown. The item.description is not appended or it seems that the append section is completely ignored.

Your help is greatly appreciated.

도움이 되었습니까?

해결책

$('.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);
} }           
 );

DEMO http://jsfiddle.net/skhan/Yw2Y7/3/

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top