如何在JQuery自动完成UI中显示Json数据? [英] How to display Json Data in JQuery autocomplete UI?
本文介绍了如何在JQuery自动完成UI中显示Json数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用jquery自动完成ui,并且我正在以json格式获取数据
i am using jquery autocomplete ui and i am getting data in json format like this
[{"organization_name":"health info"},{"organization_name":"Canada health"},{"organization_name": "org 1"}]
这是我的jquery代码,无法正确显示json数据
Here is my jquery code which is not displaying json data properly
$('input[name=profileOrg]').autocomplete({
source:'CHI_custom/customScripts/getorgname.php',
dataType: 'json',
minLength:2
});
任何人都可以帮助显示如何在自动完成的textboX下显示数据吗?
can anyone help to how can display data bellow the auto complete textboX?
推荐答案
您需要更改自动填充显示项目的方式
You need to change the way autocomplete shows the item
$('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);
};
有关jQuery文档的更多信息: http://jqueryui.com/autocomplete/#custom-data
More info on the jQuery documentation: http://jqueryui.com/autocomplete/#custom-data
这篇关于如何在JQuery自动完成UI中显示Json数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文