简体   繁体   English

如何从jquery-autocomplete中检索两个值

[英]How can I retrieve two values from jquery-autocomplete

I need my application to auto-complete on a company name, but also fill in a hidden form field with the ID of that company selected. 我需要我的应用程序自动完成公司名称,而且还需要在隐藏表格字段中填写所选公司的ID。

I believe it's possible to return pair values, with the pipe separator, such as........ 我相信可以使用管道分隔符来返回对值,例如........

Microsoft|10
Oracle|20
Sybase|30

And indeed this seems to work, but I don't know how to access the 2nd argument. 确实这似乎可行,但是我不知道如何访问第二个参数。

Everything should be returned within your select function. 一切都应在您的select函数中返回。 Your select function should be similar to this: 您的选择功能应与此类似:

function autoCompleteSelected(event, item, formatted) 
{
   item[0]; // Should be Microsoft
   item[1]; // Should be 10;
}

Then to specify the select function: 然后指定选择功能:

$("#autoCompleteField").autocomplete(url).result("autoCompleteSelected");

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM