【发布时间】:2016-08-20 09:15:17
【问题描述】:
我在一个旧的(相当大的)asp.net web-forms 项目中使用 Tag-It、jQuery Auto-Complete 和 jQuery Ajax。
一切都很完美,但在我达到目标之前还需要完成一件事。从自动完成下拉列表中选择标签(单词或单词)后,我想显示一个自动完成列表,其中包含对下一个标签(又是单词或单词)的建议。 (手动输入百分号会给我想要的行为,但我的用户不会对那个解决方案感到满意。)
我一直在搜索但没有成功,到目前为止我的所有尝试都失败了。
下面提供了我正在使用的代码。我尝试在 afterTagAdded 方法中添加很多不同的东西。当前的尝试是在jquery-ui 1.11.4. 中给我一个“Object expected” 异常
如果有人能指出我正确的方向,将不胜感激。 我不是 javascript 和 jQuery 方面的专家。
$(document).ready(function () {
var currentlyValidTags = [];
$(".TagItInput").tagit({
autocomplete: {
source: function (request, response) {
$.ajax({
type: "POST",
url: "AutoCAdvTest3.aspx/GetTexts",
data: JSON.stringify({ text: request.term, tags: $(".TagItInput").tagit("assignedTags") }),
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (msg) {
currentlyValidTags = msg.d;
response(msg.d);
}
});
},
minLength: 0
},
beforeTagAdded: function (event, ui) {
// Only allow tags from the completion list
if ($.inArray(ui.tagLabel, currentlyValidTags) == -1) {
return false;
}
},
afterTagAdded: function (event, ui) {
// without this line I get an error saying that AutoComplete is not initialized
$(".TagItInput").autocomplete();
// but.... Search method fails anyway
$(".TagItInput").autocomplete("search", "%");
},
});
$(".ui-autocomplete-input").focus();
});
【问题讨论】:
标签: javascript jquery asp.net jquery-autocomplete tag-it