jQuery UI的自动完成与价值观 [英] jQuery UI Autocomplete with values

查看:100
本文介绍了jQuery UI的自动完成与价值观的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是它在某种程度上可以设置一个值(值/文本作为一个组合框)的jQuery用户界面自动完成?

Is it somehow possible to set a value (value/text as in a combobox) in jQuery UI Autocomplete?

我需要从自动完成框中选择的项目得到了DB ID。

I need to get a DB id from the selected item in the Autocomplete box.

在此先感谢!

推荐答案

您真的不能,至少就我所看到的,设置jQueryUI的自动完成构件的值,但是你可以用小部件设置某些其它元件上在一个隐藏字段的属性或者一个属性的值

You really can't, at least as far as I've seen, set a value in the jQueryUI autocomplete widget, but you can use the widget to set the value of an attribute in a hidden field or maybe an attribute on some other element.

下面是一个快速的jsfiddle 我放在一起向世人证明它。希望这可以帮助。

Here's a quick jsFiddle I put together to demostrate it. Hopefully this can help.

我的例子是基于jQueryUI的自动完成示例自定义数据和显示。基本上,它假设你得到一些数据阵列从服务后面,或者它从服务器端呈现。在您的数据阵列,你有一个显示器领域,一个重要的价值和你的数据库ID。键值真的是没有必要的。但是,当你在自动完成列表中选择一项,你可以捕捉什么在自动完成的事件选中,然后适当地处理数据。我存储在'身份证'的价值,我在一个隐藏字段数组,但你可以不同的方式处理它。

My example is based on the jQueryUI AutoComplete example for "Custom Data and Display". Basically, it assumes you get some array of data back from a service or it's rendered from the server-side. In your array of data, you have a display field, a key value and your DB ID. The key value really isn't necessary. But when you select an item in your autocomplete list, you can capture what was selected in the autocomplete's select event and then handle the data appropriately. I stored the 'id' value in my array in a hidden field, but you can handle it differently.

希望这有助于!

这篇关于jQuery UI的自动完成与价值观的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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