jquery-ui 自动完成零星行为
下面是我的自动完成代码。问题是它大部分都有效。假设我有一堆结果,例如 test1、test2、test3 等。如果我输入“t”,它们就会弹出,当我在“te”中输入 e 时,它们就会消失。然后,如果我输入“s”,它会进一步缩小范围。它也不总是第二个字母。看起来只是零星的。请帮忙。我已经确认返回的数据是可靠的,因此后端没有任何数据。
//Server autocomplete
$("#txtSearchServer").keyup(function (event) {
$.ajax({
url: 'edit/EditService.svc/SearchServers',
type: 'GET',
data: { 'term': $("#txtSearchServer").val() },
dataType: 'json',
success: function (data) {
var listServers = [];
$.map(data.d, function (item) {
///working here to do server autocomplete!!!!!!!
listServers.push(item.ServerName);
$("#txtSearchServer").autocomplete({
source: listServers
});
});
},
error: function (a, b, c) {
$('.Toast').html('Error Retreiving Servers for autocomplete!');
}
});
});
Below is the code for my autocomplete. The problem is that it mostly works. Say I have a bunch of results that are like test1, test2, test3, etc. If I type "t" they popup, when I put an e in "te" they disappear. Then if I put in the "s" it narrows it down further. it's not always the second letter either. It just seems sporadic. Please help. I have confirmed the data coming back is solid, so it's nothing on the backend.
//Server autocomplete
$("#txtSearchServer").keyup(function (event) {
$.ajax({
url: 'edit/EditService.svc/SearchServers',
type: 'GET',
data: { 'term': $("#txtSearchServer").val() },
dataType: 'json',
success: function (data) {
var listServers = [];
$.map(data.d, function (item) {
///working here to do server autocomplete!!!!!!!
listServers.push(item.ServerName);
$("#txtSearchServer").autocomplete({
source: listServers
});
});
},
error: function (a, b, c) {
$('.Toast').html('Error Retreiving Servers for autocomplete!');
}
});
});
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
看看你正在做的 asp.net 代码,
所以这应该适合你:
Looking at your code you are doing asp.net
SO this should work for you:
这是答案: https://gist.github.com/1140631 应该可以解决这个问题。
编辑:我还想知道为什么你要动态预取结果,你不能立即获得完整列表吗?还是数据太多了?
Here is the answer: https://gist.github.com/1140631 that should solve it.
EDIT: I was wondering also why are you dynamically prefetching results, can't you get full list right away? Or is it to much data?