這篇文章主要介紹了ajax請求后臺得到j(luò)son數(shù)據(jù)后如何動態(tài)生成樹形下拉框,具有一定借鑒價值,感興趣的朋友可以參考下,希望大家閱讀完這篇文章之后大有收獲,下面讓小編帶著大家一起了解一下。

成都創(chuàng)新互聯(lián)于2013年創(chuàng)立,先為汝南等服務(wù)建站,汝南等地企業(yè),進行企業(yè)商務(wù)咨詢服務(wù)。為汝南企業(yè)網(wǎng)站制作PC+手機+微官網(wǎng)三網(wǎng)同步一站式服務(wù)解決您的所有建站問題。
如下所示:
<select id="cc" class="easyui-combotree" name="rempId" data-options="required:true"></select>
<script>
$(function(){
$.ajax({
url:"departmentAction_getAllDep.action",
type:"post",
success:function(result){
//console.log(result);
$("#cc").combotree('loadData',b1(result));
}
});
$("#cc").combotree({
animate:true,
//選擇樹節(jié)點觸發(fā)事件
onSelect : function(node) {
n = node;
//返回樹對象
var tree = $(this).tree;
//選中的節(jié)點是否為葉子節(jié)點,如果不是葉子節(jié)點,清除選中
var isLeaf = tree('isLeaf', node.target);
if (!isLeaf) {
//清除選中
$("#cc").combotree('clear');
}
}
});
});
var tree = {
id:'',
text:'',
state:'',
checked:'',
iconCls:'',
attributes:'',
children:''
}
function b1(result){
var t = [];
$.each(result,function(index,dept){
t[index] = b2(dept);
});
return t;
}
function b2(dept){
var tree = new Object();
tree.id = dept.depId;
tree.text = dept.depName;
tree.state = 'closed';
tree.checked = 'false';
if(dept.employees.length != 0){
tree.children = b3(dept.employees);
}else{
tree.children = [];
}
return tree;
}
function b3(employees){
var easyTree = [];
$.each(employees,function(index,item){
easyTree[index] = b4(item);
});
return easyTree;
}
function b4(item){
var tree = new Object();
tree.id = item.empId;
tree.text = item.empName;
if(item.empSex == "男"){
tree.iconCls = 'icon-nan';
}else{
tree.iconCls = 'icon-female';
}
return tree;
}
</script>department表中的dept_id作為employee表中有的外鍵,生成的Department.java類中有Set<employee>對象。從后臺查詢部門表,得到List<Department>集合,通過struts2配置:
<action name="departmentAction_*" class="com.chinasoft.action.DepartmentAction" method="{1}">
<result name="getAllDep" type="json">
<param name="root">list</param>
</result>
</action>轉(zhuǎn)成json格式后,傳到j(luò)sp頁面,在前臺頁面中處理json數(shù)據(jù),動態(tài)生成下拉樹。
感謝你能夠認真閱讀完這篇文章,希望小編分享的“ajax請求后臺得到j(luò)son數(shù)據(jù)后如何動態(tài)生成樹形下拉框”這篇文章對大家有幫助,同時也希望大家多多支持創(chuàng)新互聯(lián),關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道,更多相關(guān)知識等著你來學習!
網(wǎng)站欄目:ajax請求后臺得到j(luò)son數(shù)據(jù)后如何動態(tài)生成樹形下拉框
轉(zhuǎn)載來源:http://www.yijiale78.com/article16/gsogdg.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站建設(shè)、關(guān)鍵詞優(yōu)化、服務(wù)器托管、定制開發(fā)、App設(shè)計、動態(tài)網(wǎng)站
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)