1

我正在尝试使用支持 AJAX的DevBridge jQuery 自动完成插件。

我已经创建了所有必需的部分,但插件没有给我任何结果。控制台没有给我任何错误。

function initializeSubjectAutocomplete()
{
    /* Add field */

    realSubjectSelector = $('#containerForm select#subject');
    realSubjectSelector.hide();
    realSubjectSelector.after('<input type="text" placeholder="Subject" id="subjectAutocomplete" name="subjectAutocomplete">');

    /* Autocomplete */

    $('#containerForm input#subjectAutocomplete').autocomplete(
        {
            serviceUrl: 'getAutocompleteThreads',
            dataType: 'jsonp',
            minChars: 3,
            onSelect: function (suggestion){realSubjectSelector.val(suggestion.data);}
        }
    );
}

我的 getAutocompleteThreads 的典型结果格式如下:

{
query: "resolvi",
suggestions: [
    { value: "Not resolving Symlinks at all", data: "13102" },
    { value: "Resolving inter-library dependencies", data: "12079" },
    { value: "Resolving static lib dependency at executable link time", data: "13098" },
    { value: "help needed in resolving this pipeline problem", data: "59531" },
    { value: "Resolving coincident faces - linear & quadratic quarilaterals", data: "68186" }
]
}

感谢您的时间,

菲利克斯

4

1 回答 1

0

也许你没有给 DOM 从插入#subjectAutocomplete到执行更新的autocomplete()时间。

尝试替换以下代码:

realSubjectSelector.after('<input type="text" placeholder="Subject" id="subjectAutocomplete" name="subjectAutocomplete">');

    /* Autocomplete */

    $('#containerForm input#subjectAutocomplete').autocomplete(

对于这个:

$('<input type="text" placeholder="Subject" id="subjectAutocomplete" name="subjectAutocomplete">').insertAfter(realSubjectSelector).autocomplete(
于 2013-10-21T16:04:02.727 回答