在 jquery 自动完成中处理没有结果 [英] Handling no results in jquery autocomplete
本文介绍了在 jquery 自动完成中处理没有结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
嘿,当用户当前查询没有结果时,我正在尝试返回一条消息!我知道我需要利用 keyup 事件,但看起来插件正在使用它
Hey I'm trying to return a message when there are no results for the users current query! i know i need to tap into the keyup event, but it looks like the plugin is using it
推荐答案
您可以尝试提供解析选项(处理数据解析的函数),并在没有返回要解析的结果时执行您需要的操作.
You could try supplying a parse option (function to handle data parsing) and do what you need when no results are returned to parse.
此示例假设您要返回一组包含 FullName 和 Address 属性的 JSON 对象.
This example assumes you're getting back an array of JSON objects that contain FullName and Address attributes.
$('#search').autocomplete( {
dataType: "json",
parse: function(data) {
var array = new Array();
if (!data || data.length == 0) {
// handle no data case specially
}
else {
for (var i = 0; i < data.length; ++i) {
var datum = data[i];
array[array.length] = {
data: datum,
value: data.FullName + ' ' + data.Address,
result: data.DisplayName
};
}
}
return array;
}
});
这篇关于在 jquery 自动完成中处理没有结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文