jquery autocomplete transformResult自动焦点属性不起作用

Kam*_*ini 5 javascript jquery-plugins jquery-autocomplete

现在它看起来像这样 在此输入图像描述

我正在jquery自动完成下面是我的代码,我想搜索城市.

jQuery('#citySearch').autocomplete({
        serviceUrl: basePath + '/selectMycities.json',
        paramName: "tagName", // 
        onSelect: function(suggestion) {
            cityID = suggestion.data;
            cityId=cityID;
            jQuery("#cityId").val(cityID);
            return false;
        },
        transformResult: function(response) {

            return {

                suggestions: jQuery.map(jQuery.parseJSON(response), function(item) {
                    return {
                        value: item.cityName,
                        data: item.cityId,
                        id: item.cityId
                    };

                })
            };
        }
    });
Run Code Online (Sandbox Code Playgroud)

现在在上面的自动完成中我想将autoFocus设置为true但它不起作用.请帮忙.

它应该像第二张图像

在此输入图像描述

Kam*_*ini 4

我参考这些https://www.devbridge.com/sourcery/components/jquery-autocomplete/找到了解决方案

我使用了 autoSelectFirst 属性,得到了像第二张图片一样的受人尊敬的结果。

autoSelectFirst:如果设置为 true,则显示建议时将选择第一个项目。默认值 false。

jQuery('#citySearch').autocomplete({
        autoSelectFirst: true,
        serviceUrl: basePath + '/selectMycities.json',
        paramName: "tagName", // 
        onSelect: function(suggestion) {
            cityID = suggestion.data;
            cityId=cityID;
            jQuery("#cityId").val(cityID);
            return false;
        },
        transformResult: function(response) {

            return {

                suggestions: jQuery.map(jQuery.parseJSON(response), function(item) {
                    return {
                        value: item.cityName,
                        data: item.cityId,
                        id: item.cityId
                    };

                })
            };
        }
    });
Run Code Online (Sandbox Code Playgroud)