我正在尝试使用DevBridge jQuery Autocomplete Plugin和AJAX支持。
我创建了所有必需的部分,但插件没有给我任何结果。 控制台没有给我任何错误。
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" }
]
}
感谢您的时间,
菲利克斯
答案 0 :(得分:0)
当你插入#subjectAutocomplete
然后只是执行autocomplete()
时,你可能没有给DOM时间来更新DOM。
尝试替换以下代码:
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(