jquery UI 自动完成 - 扩展数据?
我想使用 Jquery 的 UI 自动完成 但具有一些附加功能:在用户选择建议的项目后,我还想在某些 html 元素中显示与该项目相关的附加数据(例如,如果正在搜索联系人数据库,那么我想显示联系人的电子邮件、地址...)。
有办法做到这一点吗?
预先感谢,
Ile
编辑:
我想提供我实际需要的更多详细描述:
当用户开始搜索联系人时,作为数据库的结果,我想返回联系人的 ID 和全名。用户选择某个联系人后,将调用 ajax 函数,并使用其 ID 检索所选联系人的所有详细信息。但我不知道如何执行以下操作:
作为数据库的结果,以 JSON 结果返回联系人的 ID 和全名(可能我会找到获得正确格式的解决方案,但我不知道需要如何将其传递给自动完成脚本)
如何处理结果数据,以便仅在选择特定联系人时才显示全名和 ID,以便我可以检索特定联系人的完整详细信息
I would like to use Jquery's UI autocomplete but with some additional functions: after user selects suggested item, I would also like to display additional data related with that item (for example if database of contacts are being searched, then I'd like to display contact's email, addres...) in some html element.
Is there a way to accomplish this?
Thanks in advance,
Ile
EDIT:
I'd like to provide more detail description of what I actually need:
When user starts searching contacts, as a result from database I would like to return contact's ID and Full Name. After user selects certain contact, then ajax function is called and it retrieves all details from selected contact using it's ID. But I don't know how to do following:
As a result from database return the ID and Full Name of contact as a JSON result (probably I would find the solution to get the right format, but I don't know how it needs to be passed to Autocomplete script)
How to handle the result data so that I display only full name and ID is used only when certain contact is selected, so that I can retrieve full details of certain contact
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
看看 其事件:您可以为
select 添加处理程序
事件并在触发后显示您的所有信息。Have a look at its events: You can add a handler for the
select
event and display all your informations once it fires.您可以在 formatMatch 函数中指定额外的数据。该参数必须是一些分隔符分隔的字符串。稍后在 .result 函数中,该函数采用 3 个参数 [事件、数据、格式化],您可以通过按分隔符使用拆分格式化来检索它并填充所需的值。
You can specify extra data in formatMatch function. The parameter must be some delimiter separated string. Later in .result function , which takes 3 arguments [event, data, formatted], you can retrieve it by splitting the formatted by the delimiter use and populate the required values.