无法设置属性' _renderItem'未定义的

时间:2015-04-28 05:58:43

标签: javascript jquery ajax

这是我的代码...... 任何人都可以帮助我吗?

  

$(document).ready(function(){

//$('#search input[name="filter_name"]').attr("x-webkit-speech", "x-webkit-speech")
$('#search input[name="input-search-menu"]').autocomplete({
    source: function(request, response) {
        $.ajax({
            url: 'index.php?route=module/search_suggestion/ajax',
            dataType: 'json',
            data: {
                keyword: request.term
            },
            success: function(json) {
                response($.map(json, function(item) {
                    return {
                        fields: item.fields,
                        value: item.href
                    }
                }));
            }
        });
    },
    minLength: 1,
    select: function(event, ui) {
        if (ui.item.value == "") {
            return false;
        } else {
            location.href = ui.item.value;
            return fse;
        }
    },
    open: function() {
        $(this).removeClass("ui-corner-all").addClass("ui-corner-top");
    },
    close: function() {
        $(this).removeClass("ui-corner-top").addClass("ui-corner-all");
    },
    focus: function(event, ui) {
        $('#search input[name="filter_name"]').val(ui.item.label);
        return false;
    }
}).data("ui-autocomplete")._renderItem = function(ul, item) {

    var elements = [];
    $.each(item.fields, function(field_name, field) {
      if (field != undefined && field[field_name] != undefined && field[field_name]) {

        var field_html = '';            
        if (field_name == 'price') {
          if (field.special) {
            field_html = '<span class="price-old">' + field.price + '</span><span class="price-new">' + field.special + '</span>';
          } else {
            field_html = field.price;
          } 
        } else {
          field_html = field[field_name];
        }

        if (field.label != undefined && field.label.show != undefined && field.label.show) {
          field_html = '<span class="label">' + field.label.label + '</span>' + field_html;
        }
        if (field.location != undefined && field.location == 'inline') {
          field_html = '<span class="' + field_name + '">' + field_html + '</span>';
        } else {
          field_html = '<div class="' + field_name + '">' + field_html + '</div>';
        }

        elements.push({sort: field.sort, html: field_html});
      }
    });

    // sort
    elements.sort(function(a, b){return a.sort-b.sort});

    // implode
    var elements_html = '';
    $.each(elements, function(index, element) {
      if (element != undefined) {
        elements_html = elements_html + element.html;
      }
    });     

    return $("<li></li>")
        .data("item.autocomplete", item)
        .append('<a class="search-suggestion">' + elements_html + '</a>')
        .appendTo(ul);
};

});

`我无法设置属性&#39; _render_item&#39;在我的js文件上。这阻止了我的js文件工作。任何人都可以帮我解决我的代码吗?

提前致谢

1 个答案:

答案 0 :(得分:1)

  

有关自动填充的某些命名约定已弃用   v1.9中的jQuery UI已在v1.10中完全删除(参见   http://jqueryui.com/upgrade-guide/1.10/#autocomplete)。

您可以在Cannot set property '_renderItem' of undefined jQuery UI autocomplete with HTML查看,因为它解释得非常好。 :)