這篇文章主要介紹了ajax請求后臺得到j(luò)son數(shù)據(jù)后如何動態(tài)生成樹形下拉框,具有一定借鑒價值,感興趣的朋友可以參考下,希望大家閱讀完這篇文章之后大有收獲,下面讓小編帶著大家一起了解一下。
固陽網(wǎng)站建設(shè)公司創(chuàng)新互聯(lián),固陽網(wǎng)站設(shè)計制作,有大型網(wǎng)站制作公司豐富經(jīng)驗。已為固陽上千家提供企業(yè)網(wǎng)站建設(shè)服務(wù)。企業(yè)網(wǎng)站搭建\外貿(mào)網(wǎng)站制作要多少錢,請找那個售后服務(wù)好的固陽做網(wǎng)站的公司定做!如下所示:
<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)生成下拉樹。
感謝你能夠認(rèn)真閱讀完這篇文章,希望小編分享的“ajax請求后臺得到j(luò)son數(shù)據(jù)后如何動態(tài)生成樹形下拉框”這篇文章對大家有幫助,同時也希望大家多多支持創(chuàng)新互聯(lián)網(wǎng)站建設(shè)公司,,關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道,更多相關(guān)知識等著你來學(xué)習(xí)!
網(wǎng)站題目:ajax請求后臺得到j(luò)son數(shù)據(jù)后如何動態(tài)生成樹形下拉框-創(chuàng)新互聯(lián)
文章URL:http://muchs.cn/article12/dsepdc.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供域名注冊、營銷型網(wǎng)站建設(shè)、服務(wù)器托管、品牌網(wǎng)站建設(shè)、網(wǎng)站導(dǎo)航、品牌網(wǎng)站設(shè)計
聲明:本網(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)
猜你還喜歡下面的內(nèi)容