Javascript 渲染自定义自动完成结果

Javascript 渲染自定义自动完成结果,javascript,jquery,json,jquery-ui,autocomplete,Javascript,Jquery,Json,Jquery Ui,Autocomplete,我有以下代码: jQuery("#hotelName").autocomplete({ serviceUrl:'xxxxxxxxxxxxxxxxxxxxxxxx', minChars:1, delimiter: /(,|;)\s*/, // regex or character maxHeight:200, zIndex: 9999, appendTo:

我有以下代码:

jQuery("#hotelName").autocomplete({
            serviceUrl:'xxxxxxxxxxxxxxxxxxxxxxxx',
            minChars:1,
            delimiter: /(,|;)\s*/, // regex or character
            maxHeight:200,
            zIndex: 9999,
            appendTo: "#ui-front"
         }).data( "ui-autocomplete" )._renderItem = function( ul, item ) {
                console.log(item);
              return jQuery( "<li>" )
                .data( "ui-autocomplete-item", item )
                .append( "<a>" + item.label + "<br>" + item.desc + "</a>" )
                .appendTo( ul );
            };
我使用的是
jqueryui自动完成1.2.9

“自动完成”正在正常工作,不会出现以下问题:

jQuery("#hotelName").autocomplete({
                serviceUrl:'xxxxxxxxxxxxxxxxxxxxxxxx',
                minChars:1,
                delimiter: /(,|;)\s*/, // regex or character
                maxHeight:200,
                zIndex: 9999,
                appendTo: "#ui-front"
             });
但我想应用自定义渲染。你知道有什么问题吗

编辑:


我试图将jQuery UI Auto Complete升级到最新版本,但这对我没有帮助。

要从一个jQuery对象中获取小部件实例(您要调整的renderItem属性),该对象包含应用此小部件的元素,您应该使用小部件的方法,如中所示。例如:

$('#input_to_autocomplete')
  .autocomplete(widgetOptions) // applying the widget
  .autocomplete('instance')    // getting the widget's instance
  ._renderItem = function(ul, item) { /*... */ }; // augmenting the display function

谢谢你的回复。我更改了代码,我在控制台中没有收到任何错误,到目前为止,这是很好的,自动完成正在工作,但项目没有按预期呈现,而且我在控制台上没有收到任何关于此
console.log(项目)的内容@SzamDev说实话,这对我来说没什么意义。你能准备好小提琴来展示你的作品吗?@SzamDev做得很好,原作有很多错误(你已经检查过了)。非常感谢你,现在一切都清楚了。我刚刚注意到您将jQuery升级到了2.1.0,有必要吗?@SzamDev没有,没有必要<代码>jQuery UI 1.11
需要
jQuery 1.6+
$('#input_to_autocomplete')
  .autocomplete(widgetOptions) // applying the widget
  .autocomplete('instance')    // getting the widget's instance
  ._renderItem = function(ul, item) { /*... */ }; // augmenting the display function