2013-03-08 108 views
0

我使用jQuery的自动完成UI和我在JSON格式类似这样的如何在JQuery自动完成UI中显示Json数据?

[{"organization_name":"health info"},{"organization_name":"Canada health"},{"organization_name": "org 1"}] 

及彼数据是不显示JSON数据我jQuery代码正确

$('input[name=profileOrg]').autocomplete({ 
        source:'CHI_custom/customScripts/getorgname.php', 
        dataType: 'json', 
        minLength:2 

       }); 

谁能帮助哪有显示数据在自动完成textboX?

+4

有你阅读文档 – Daisy 2013-03-08 18:50:17

+0

你需要'标签:STR,值:str'对在你的JSON中。 – Ohgodwhy 2013-03-08 18:51:47

+0

@Ohgodwhy你的意思是这样的'[{lable:organization_name,value:health info},{lable:organization_name,value:value2}]' – user1878049 2013-03-08 19:00:09

回答

0

您需要更改自动完成的方式显示项目jQuery的文档上

$('input[name=profileOrg]').autocomplete({ 
    source:'CHI_custom/customScripts/getorgname.php', 
    dataType: 'json', 
    minLength:2, 
    select: function (event, ui) { 
     $(this).val(ui.item.organization_name); 
     return false; 
    } 
}) 
.data("autocomplete")._renderItem = function (ul, item) { 
     return $("<li></li>") 
      .data("item.autocomplete", item) 
      .append('<a>' + item.organization_name + '</a>') 
      .appendTo(ul); 
}; 

更多信息:http://jqueryui.com/autocomplete/#custom-data

+0

谢谢你的代码对我来说非常感谢你...你是我的救世主 – user1878049 2013-03-08 19:13:28

+0

你的代码工作正常,但是当我从列表中选择名字的时候,名字不会显示在文本框中 – user1878049 2013-03-08 19:22:49

+0

你是对。您需要将'select'选项添加到该函数。回答编辑。 – 2013-03-08 19:28:31