0

我在这个网站上看到了类似的问题,但我无法弄清楚我的代码有什么问题。我正在使用 jquery 自动完成功能,除了不显示该类别外,它工作正常。我尝试在 firebug 中进行调试,但看起来我从来没有在 _renderMenu 中找到“var self = this”

$.widget("custom.catcomplete", $.ui.autocomplete, {
    _renderMenu: function (ul, items) {
        var self = this;
        var currentCategory = "";
        $.each(items, function (index, item) {
            if (item.category != currentCategory) {
                ul.append("<li class='ui-autocomplete-category'>" + item.category + "</li>");
                currentCategory = item.category;
            }
            self._renderItem(ul, item);
        });
    }
});

$("#m_tSearchEngine").autocomplete({
    source: function (request, response) {
        $.ajax({
            url: '../../Class/SearchEngine.asmx/GetSearchEngineItems',
            data: "{ 'criteria': '" + $("#m_tSearchEngine").val() + "'}",
            dataType: "json",
            type: "POST",
            contentType: "application/json; charset=utf-8",
            success: function (data) {
                var c = eval(data.d);
                response($.map(c, function (item) {
                    return {
                        label: item.Name,
                        value: item.Name,
                        id: item.Id,
                        category: item.category,
                        subCategory: item.Type,
                        secondSubCategory: item.SecondType
                    }
                }))
            },
            error: function (XMLHttpRequest, textStatus, error) {
                //alert(textStatus);
            }
        });
    },
    minLength: 1,
    select: function (event, ui) {
        location.href = "../../Literature/Pages/Literature.aspx?category=" + ui.item.category + "&subCategory=" + ui.item.subCategory + "&secondSubCategory=" + ui.item.secondSubCategory;
    }
});

这就是我的 json 的样子:

[{"category":1,"Id":49,"Name":"4800H","Type":7,"SecondType":0},{"category":1,"Id":86,"Name":"4900H","Type":7,"SecondType":0},{"category":2,"Id":1342,"Name":"D-DA1000HP-PSM(__)DBF","Type":25,"SecondType":54}]
4

1 回答 1

1

我终于找到了我的问题。

而不是使用

$("#m_tSearchEngine").autocomplete

我不得不使用

$("#m_tSearchEngine").catcomplete
于 2012-08-27T17:53:01.080 回答