如何中止当前的自动完成数据呈现 [英] How to abort current autocomplete data rendering

查看:69
本文介绍了如何中止当前的自动完成数据呈现的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我遇到了jquery autocomplete的问题,其中要求是从数据库中提取数千条记录的列表并在自动完成下拉列表中呈现。



我在keydown事件上绑定数据加载,当我输入时间间隔为1秒或更短的任何字符时,它分别为每个字符渲染结果。

示例i按'a'而不是'j'而不是'a'而不是'x'而不是它将渲染结果最初匹配'a'而不是重新加载'aj'的结果而不是'aja'比'ajax'的最后一个。



我想要的行为就像是我按下另一个字符而不是取消旧请求并只渲染新结果。对于同样的尝试使用.abort()方法取消ajax调用,但它仍然是先渲染旧结果而不是使用新调用刷新结果。即使我在渲染旧结果之前输入了第二个字符。



请帮我解决这个问题。

Hi,

I am having an issue with jquery autocomplete where the requirement is to pull a list of thousands records from database and to render on autocomplete dropdown list.

I have bind data load on keydown event, and when i type any character with a time interval of 1 sec or less than it render the result for every character respectively.
Example i press 'a' than 'j' than 'a' and than 'x' than it will render result initially matching 'a' than reload with result for 'aj' than for 'aja' than last for 'ajax'.

I want the behavior like if i press another character than it should cancel older request and render only new result. And for the same i tried with cancel ajax call using .abort() method, but still it is rendering old result first than refresh result with new call. Even i entered second another character before rendering old result.

Please help me to solve this issue.

推荐答案

我想知道真正的要求是什么:1 )在UI中提供来自数千条记录的选择,或者2)使用完全自动完成来帮助这样的选择。



如果你面临的要求是#1 ,这只是一个糟糕的要求。如果是#2,则完全是白痴要求。自动完成机制,按设计而言只是常识,应该相当快。即使用户很快得到它,如果可能性的总数是几千个,那么操作人员几乎不能批判性地考虑在运行中基于自动完成的选项之间的选择。


在这两种情况下,唯一合理的解决方案就是不这样做。而你正试图用编程拐杖代替真正的解决方案 - 中止自动完成。它将导致你无处可去。粗略地说,在实际使用中,将近100%的自动完成操作将被中止。



正确的解决方案是重新设计UI。有很多种可能性。例如,如果结果集中有数千条记录,则可以对结果集执行其他查询。如果这是所有数据,您只需要一些查询。您还可以使用一些带分页的列表视图,并使用用户选择的不同排序条件。这一切还取决于数据的语义。



请不要重复常见错误,不要告诉我这是你要求的遇到。然后与那些给你这个要求的人交谈。如果他们坚持,让他们跟我说话。



-SA
I wonder what is the real requirement: 1) to provide a choice in a UI from thousands of records, or 2) use exactly autocomplete to assist such choice.

If the "requirement" you faced is #1, this is just a bad "requirement". If it is #2, it is completely idiotic "requirement". The autocomplete mechanism, by design and just be common sense, is supposed to be fairly fast. Even if the user got it quickly, the human operator is hardly capable of critically considering the choice between some autocomplete-based options on the fly, if the total number of possibilities is some thousands.

In both cases, the only reasonable solution is not doing it. And you are trying to substitute the real solution with a programming crutch — aborting the autocomplete. It will lead you nowhere. Roughly speaking, in real use, nearly 100% of autocomplete operations will be aborted.

The right solution is to redesign the UI. There are many possibilities. For example, you can perform additional query on the result set, if thousands of record is the result set. If this is all the data, you just need some query. You can also use some list view with paging, with different sorting criteria chosen by the user. It all also depends on the semantic of the data.

And please don't repeat the common mistake, don't tell me that this is the requirement you got to meet. Then talk to people who gave your this "requirement". If they insist, let them talk to me.

—SA


这篇关于如何中止当前的自动完成数据呈现的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆