TypeError:$(...)。autocomplete(...)。data(...)未定义 [英] TypeError: $(...).autocomplete(...).data(...) is undefined

查看:88
本文介绍了TypeError:$(...)。autocomplete(...)。data(...)未定义的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在使用jQuery自动完成时发现错误。

I found error when using jQuery autocomplete.

控制台中的此通知错误


TypeError:$(...)。autocomplete(...)。data(...)未定义
})。data(ui-autocomplete)._ renderItem = function(ul, item){

TypeError: $(...).autocomplete(...).data(...) is undefined }).data( "ui-autocomplete" )._renderItem = function( ul, item ) {

代码:

Site Name <br/>

<input type="text" name="site_name" id="site_name"><br/>

<input type="hidden" name="site_id" id="site_id">

$().ready(function () {
    $("#site_name").autocomplete({
        source: function (request, response) {
            $.ajax({
                url: "get_site2.php",
                dataType: "json",
                data: {
                    term: request.term
                },
                beforeSend: function () { // add this
                    showLoading("remove");
                    console.log("remove");
                },
                success: function (data) {
                    response(data);
                }
            });
        },
        minLength: 2,
        select: function (event, ui) {
            $("#site_name").val(ui.item.label);
            $("#site_id").val(ui.item.name);
            return false;
        },
        open: function () {
            $(this).removeClass("ui-corner-all").addClass("ui-corner-top");
        },
        close: function () {
            $(this).removeClass("ui-corner-top").addClass("ui-corner-all");
        }
    }).data("ui-autocomplete")._renderItem = function (ul, item) {
        return $("<li></li>")
            .data("ui-autocomplete-item", item)
            .append("<a>" + item.label + "</a>")
            .appendTo(ul);
    };

});

我很困惑,我已经搜索并尝试这个问题但它没有解决它。

I confused, I already search and try this question but it did not fix it.

推荐答案

对不起,这个修复可能有点晚了..但其他人遇到这个问题。

Sorry this fix might be a bit late .. but for the other guys running into this problem.

只是改变

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

})._renderItem = function (ul, item) {

这可以解决问题。

在某些情况下,它看起来像这样

In some cases it will look like this

.autocomplete().data("uiAutocomplete")._renderItem =  function( ul, item ) 

将其更改为

.autocomplete()._renderItem = function( ul, item ) 

这篇关于TypeError:$(...)。autocomplete(...)。data(...)未定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆