【问题标题】:Can't override _renderItem function in jQuery UI autocomplete无法覆盖 jQuery UI 自动完成中的 _renderItem 函数
【发布时间】:2016-06-11 23:44:29
【问题描述】:

我正在尝试在 jQuery UI 自动完成中显示带有标签的图像。

我被错误卡住了

jquery-ui.js:6853 Uncaught TypeError: Cannot read property 'value' of undefined"。

然而,在我的调查过程中,发现问题出在覆盖 _renderItem 函数上——无论我在其被覆盖的实现中做什么,我都会看到同样的错误,即使我只是通过从 jQuery UI 源代码复制代码来定义它代码。

我尝试了 jQuery UI 版本 1.10.4 1.11.4 和 1.10.2,但问题仍然存在。

我认为我已经尝试了几乎所有方法,甚至制作了非常愚蠢的自动完成版本,但是,每次我使用 _renderItem 实现时,都会发生错误。

根据jQuery UI的源代码,这个错误的原因是缺少ui-autocomplete-item数据,但是我确实发送了它,所以我不知道我做错了什么。

【问题讨论】:

    标签: javascript jquery jquery-ui autocomplete


    【解决方案1】:

    这是针对 jQuery 1.10.2 的

       var autoComObj = $("#id").autocomplete({
                    minLength : 3,
                    width : 590,
                    scroll : true,
                    scrollHeight : 250,
                    matchContains : true,
                    autoFill : false,
                    cacheLength : 1,
                    source:function(request,response){//some code },
                    select:function(event,ui){//selection code }
                    });
        autoComObj.data("ui-autocomplete")._renderItem=function(ul, item){//custom renderItem code. }
    

    【讨论】:

    • 问题仍然存在,即使是完全一样的东西:$( "#automplete-1" ).autocomplete({ source: ["a", "b", "c"] }) .data("ui-autocomplete")._renderItem = function( ul, item ) { return $( "<li>" ) .data( "ui-autocomplete-item", item ) .append( "<a>" + item.label + "</a>" ) .appendTo( ul ); };
    猜你喜欢
    • 1970-01-01
    • 2018-06-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-03-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多