Jquery AutoComplete显示所有列表而不是搜索结果

时间:2016-06-28 11:59:57

标签: jquery json

我有像json这样的json自动完成源:

   $(function () {
        $('body').delegate('input.city', 'focusin', function () {
            $(this).autocomplete({
                source: function (request, response) {

                    response($.map(JSON.parse(Cityjs), function (item) {
                        return { label: item.CityName, value: item.CityID };
                    }))},
                minLength: 3
            });
        });

    });

});

现在,当我在框中搜索时,它会在列表中显示所有标签结果,而不是自动完成。但是当我使用这种方法时:

  var availableTags = ["...some content,some content..."];
    $('body').delegate('input.city', 'focusin', function () {
        $(this).autocomplete({ source: availableTags });
    });

它有效。问题是我需要从框中选择值的ID。

Cityjs 是带有CityID和CityName对的模型中的json数组。 Cityjs样本:

[{"CityID":7,"CityName":"AAA"},
{"CityID":6,"CityName":"BBB"},
{"CityID":5,"CityName":"VVV"}]

0 个答案:

没有答案
相关问题