jQuery自动完成语法?

时间:2016-04-13 04:25:10

标签: javascript jquery ajax autocomplete

我没有很多jQuery的经验,但下面是自动完成代码,它成功地在搜索结果下拉行中加粗搜索字符:

.autocomplete({
      delay: 500,
      minLength: 0,

      source: function(request, response) {
        // delegate back to autocomplete, but extract the last term
        var list = $.ui.autocomplete.filter(availableTags, extractLast(request.term));
        if (request.term) {
          regex = new RegExp('(' + extractLast(request.term) + ')', 'gi');
          list = list.map(function(item) {
            return {
              label: item.label.replace(regex, '<b>$1</b>'),
              value: item.value
            }
          })
        }
        response(list);
      },

我现在正尝试将源切换为AJAX查找。任何人都可以让我知道编辑将对以下AJAX代码进行编辑,以获得像第一个代码示例那样的粗体文本字符吗?

 .autocomplete({
      delay: 500,
      minLength: 0,

      source: function (request, response) {
                $.ajax({
                    url: 'default.aspx/fGetCityLookupData',
                    data: "{'strSearchText': '" + extractLast(request.term) + "'}",
                    dataType: "json",
                    type: "POST",
                    contentType: "application/json; charset=utf-8",
                    success: function (data) {
                        response($.map(data.d, function (item) {
                            return {
                                label: item.split('|')[1],
                                value: item.split('|')[0]
                            }
                        }))
                    },
                    error: function (response) {
                        alert(response.responseText);
                    },
                    failure: function (response) {
                        alert(response.responseText);
                    }
                });
            },

TIA 标记

1 个答案:

答案 0 :(得分:0)