jQuery UI autoComplete - 从另一个字段传递一个值
我将 jQuery UI 自动完成功能附加到一个有效的联系人字段,但现在我还需要传递一个 company_id (动态)以将搜索不仅限制为搜索字符,还限制为用户之前选择的公司。 IE 如果用户输入“jo”,则所有在 company_id 内包含“jo”的联系人都会被传递。
顺便说一句,remote.php 传回 id 和值,以便我可以填充 contact_name 和 contact_id。那部分有效。
我只是不知道如何将 company_id 字段传递给它。
$( "#contact_name ).autocomplete({ source: 'remote.php?t=contactSearch', minLength: minlen, select: function( event, ui ) { $( "#contact_id" ).val(ui.item.id ); } });
谢谢!
I'm attaching jQuery UI autocomplete to a contact field which works, but now I need to also pass a company_id (dynamcially) to restrict the search not only to the search characters but also to a company that the user has previously chosen. IE if the user enter 'jo' all contacts that contain 'jo' that are within the company_id passed.
Incidentally, remote.php passes back id, and value so I can populate both the contact_name and contact_id. That part works.
I just can't figure out how to pass it the company_id field.
$( "#contact_name ).autocomplete({ source: 'remote.php?t=contactSearch', minLength: minlen, select: function( event, ui ) { $( "#contact_id" ).val(ui.item.id ); } });
thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
经过大量研究和反复试验,这对我有用。
那么这是做什么的:
用户在此代码之前选择了一家公司(未显示),
下面的自动补全附加了 contact_name,并且还传递了 company_id。
remote.php 返回符合部分搜索条件且属于给定公司的联系人的 id 和值的数组。当用户单击某个值时,联系人姓名将被放置在自动完成字段中(没有特殊代码,自动完成会自动完成),并且 id 将被放置在 contact_id 字段中。
After much research and trail and error, this works for me.
So what this does:
The user has chosen a company before this code (not shown),
The autocomple below is attached the contact_name, and the company_id is also passed.
remote.php returns an array of both id and value of the contacts that meet the partial search criteria and belong to the given company. When the user clicks on a value, the contact name is placed in the field of the autocomplete(there is no special code for that, autocomplete does that automatically) and id is placed in the contact_id field.