質問

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