2

私のページには、データを正しく取得して表示するオートコンプリートがあります。データ: Object { custId="CUST2", invoiceNo="B1"} jquery v1.8.2 分 jQuery UI - v1.10.3

$("#invoiceNo").autocomplete({
        source : function(request, response) {
            if($.trim($(this.element).val())==""){
               return;
            }
            $.ui.autocomplete.prototype._renderMenu = function(ul, items) {
                var self = this;
                ul.append("<li><table width='100%' class='table table-condensed table-bordered' style='margin-bottom:0px;'><tr><td width='20%'><b>Invoice No</b></td><td width='20%'><b>Customer ID</b></td></tr></table></li>");
                $.each(items, function(index, item) {
                    self._renderItem(ul, item);
                });
            };
            $.getJSON("getInvoiceList.html", {
               query : $.trim($(this.element).val()),
                type:"del",
            }, response).error(function(xhr, ajaxOptions, thrownError) {

            }); 
        },
        open: function() { 
            // After menu has been opened, set width
            $('.ui-menu').width(700);
        },
        minLength : 1,
        select : function(event, ui) {
            alert(ui.item);
            $("#invoiceNo").val(ui.item.invoiceNo);
            //setCustomerDetails(ui.item.number);

            getInvoiceDetailForReturn(ui.item.invoiceNo);
            return false;
        },error: function (xhr, ajaxOptions, thrownError) {
            $.jGrowl(xhr.responseText); 
        }
    }).data("ui-autocomplete")._renderItem = function(ul, item) {               
         return $("<li></li>").data("item.autocomplete-item", item) .append("<a><table width='100%' class='table table-condensed table-hover' style='margin-bottom:0px;'><tr><td width='20%'>" + item.invoiceNo + "</td><td width='20%'>"+item.custId+"</td></tr></table></a>").appendTo(ul);
    };

最初にエラーが$(...).autocomplete(...).data(...) is undefined あり、その問題を解決します

私は変更しなければならなかったことがわかりました

data("Autocomplete" )._renderItemData = function( ul, item ) {

.data( "item.autocomplete", item )

 data("ui-autocomplete" )._renderItem = function( ul, item ) {

.data( "item.autocomplete-item", item )

ui.item オブジェクトを取得しません...

4

1 に答える 1