【发布时间】:2016-04-23 00:43:45
【问题描述】:
我有一个 .tokenInput,它使用从我的网络服务返回的数据进行搜索/自动完成;这很好用..
我的问题是,无论我在搜索什么,它总是返回来自网络服务的所有项目,而不是过滤掉那些不符合我输入的搜索字符串/标记名的项目...
...因此我尝试在 onResult: 事件中修改返回的结果,但没有成功...
关于返回的数据:
X [Objects] 数组,其中每个对象包含 id 和 name
还有……有趣的部分(脚本)
$("#articleTags").tokenInput("api/Article/GetClubTags", {
crossDomain: false,
prePopulate: $(this).data("pre"),
theme: "facebook",
preventDuplicates: false,
allowFreeTagging: true,
tokenValue: 'name',
onResult: function (items) {
if ($.isEmptyObject(items)) {
return [{ id: '0', name: $("tester").text() }]; // if tag not found on server (this works)..
} else {
var tagsearch = $("tester").text(); // for example "Norway".
var arrayMatch = items.forEach(function (itm) {
if (itm.name === tagsearch) {
console.log("FOUND > " + itm.name); // output works when i type in the correct string
return itm;
}
});
console.log(items);
return items; // just displaying all items, not filtering out those who does not match the string.
}
}
});
【问题讨论】:
标签: jquery web-services asp.net-web-api jquery-tokeninput