jQuery UI Auto建议选择问题

时间:2012-06-26 13:17:51

标签: jquery jquery-ui jquery-ui-autocomplete

我正在使用http://jqueryui.com/demos/autocomplete/#default

我的数据

[{"icd_ID":"2","icd_code":"A00","icd_desc":"Cholera","icd_yn":"N"},
        {"icd_ID":"3","icd_code":"A00.0","icd_desc":"Cholera due to Vibrio cholerae 01, biovar cholere","icd_yn":"Y"},
        {"icd_ID":"4","icd_code":"A00.1","icd_desc":"Cholera due to Vibrio cholerae 01, biovar eltor","icd_yn":"Y"},
        {"icd_ID":"5","icd_code":"A00.9","icd_desc":"Cholera, unspecified","icd_yn":"Y"}
        ]

对于“icd_desc”自动建议值,我想得到“icd_code”。

jsfiddle链接:http://jsfiddle.net/ajaypatel_aj/PRnc9/

2 个答案:

答案 0 :(得分:2)

如果您使用的是本地数据源,我会转换该数据源以符合小部件所期望的内容:

var source = $.map(availableTags1, function (el) {
    return {
        label: el.icd_desc,
        value: el.icd_code
    };
 });

 $("#tags").autocomplete({
    source: source
 });

示例: http://jsfiddle.net/sXaZX/

答案 1 :(得分:1)

您是使用服务器端脚本编写的吗?当您请求页面时,本地数据在响应中吗?所以只分出10个项目