使用 DOJO 自动完成文本框
我正在寻找一种使用 DOJO 进行文本框自动建议的简单方法。我要查询的数据库表(使用 PHP 脚本,以 JSON 形式返回)有超过 100,000 条记录,因此这确实不应该采用 FilteringSelect 或 ComboBox 的形式,因为我显然不希望用户单击向下箭头返回整个数据集。
其他库(如 JQuery 和 YUI)使其变得非常简单,但这个特别的项目是基于 DOJO 的,我不愿意引入另一个 JS 类。
I am looking for a simple method using DOJO for a textbox autosuggest. The db table that I'll be querying against (using a PHP script, returned as JSON) has over 100,000 records, so this really shouldn't be in the form of a FilteringSelect or a ComboBox as I clearly don't want the user to return the entire data set by clicking on the down arrow.
Other libraries like JQuery and YUI make it dirt simple, but this particularly project is DOJO based and I'm loath to introduce another JS class.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
它正在工作!
即使我正在查询 100,000 条记录。返回速度低于30ms。我什至将数据库大小增加到 500,000 条记录,并且自动建议速度非常可以接受(仍然低于 120 毫秒)。我确信通过在 PHP 端进行一些缓存我可以做得更好。
我最终使用了QueryReadStore和FilteringSelect。 JsonRestStore 可能会起作用,但我从 dojo 站点找到了一个简单的工作示例并从中构建。
下面是针对非常大的数据集的自动建议文本框的工作 DOJO 代码 - 简短而甜蜜:
当然,坚持
页面正文中的某处。效果很好。
再次感谢!
It's working!
Even with the 100,000 records that I'm querying against. Return speeds are under 30ms. I even bumped the database size to 500,000 records, and the auto-suggest speeds are very acceptable (still under 120ms). I'm sure I can do even better with a little caching on the PHP side.
I ended up using QueryReadStore and FilteringSelect. JsonRestStore would have probably worked, but I found a simple working example from the dojo site and built from that.
Here's working DOJO code for an auto-suggest textbox hitting a very large data set - short and sweet:
Of course, stick
<select id="vendorSelection"></select>
somwhere in the body of the page. Works great.Thanks again!
我不熟悉 jQuery 或 YUI 是如何做到这一点的,但是 Dojo 中的 ComboBox 和 FilteringSelect 有一个 pageSize 属性,可用于限制一次从商店请求的项目数量。您将在下拉列表中看到不超过该数量的项目,并附有“更多选择”和“先前选择”选项,用于翻阅其他选项(如果适用)。
将其与每次获取时查询服务器的数据存储(例如 dojox.data.QueryReadStore 或 dojox.data.JsonRestStore)放在一起,而不是预先获取所有内容的存储(例如 dojo.data.ItemFileReadStore),然后您应该能够做你想做的事。
I'm not familiar with how jQuery or YUI do it, but ComboBox and FilteringSelect in Dojo have a
pageSize
property which can be used to restrict how many items are ever requested at once from the store. You will see no more than that number of items in the drop-down, accompanied by "more choices" and "previous choices" options to page through additional choices, if applicable.Put that together with a data store that queries the server on each fetch (e.g. dojox.data.QueryReadStore or dojox.data.JsonRestStore) instead of a store that fetches everything once up-front (e.g. dojo.data.ItemFileReadStore), and you should be able to do what you want.
也许您可以让查询返回前 X 行。每次新的点击,返回 X 个新行,跳过 X。
Maybe you could make your query return the first X rows. Each new click, return X new rows, skipping X.