ajax請求后臺(tái)得到j(luò)son數(shù)據(jù)后動(dòng)態(tài)生成樹形下拉框的方法
如下所示:
<select id="cc" class="easyui-combotree" style="width:580px;" 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é)點(diǎn)觸發(fā)事件 onSelect : function(node) { n = node; //返回樹對象 var tree = $(this).tree; //選中的節(jié)點(diǎn)是否為葉子節(jié)點(diǎn),如果不是葉子節(jié)點(diǎn),清除選中 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>對象。從后臺(tái)查詢部門表,得到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頁面,在前臺(tái)頁面中處理json數(shù)據(jù),動(dòng)態(tài)生成下拉樹。
以上這篇ajax請求后臺(tái)得到j(luò)son數(shù)據(jù)后動(dòng)態(tài)生成樹形下拉框的方法就是小編分享給大家的全部內(nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持我們。
上一篇:layui的checbox在Ajax局部刷新下的設(shè)置方法
欄 目:AJAX相關(guān)
下一篇:沒有了
本文標(biāo)題:ajax請求后臺(tái)得到j(luò)son數(shù)據(jù)后動(dòng)態(tài)生成樹形下拉框的方法
本文地址:http://mengdiqiu.com.cn/a1/AJAXxiangguan/11308.html
您可能感興趣的文章
- 01-11layui的checbox在Ajax局部刷新下的設(shè)置方法
- 01-11ajax獲得json對象數(shù)組 循環(huán)輸出數(shù)據(jù)的方法
- 01-11解決ajax請求后臺(tái),有時(shí)收不到返回值的問題
- 01-11詳談ajax返回?cái)?shù)據(jù)成功 卻進(jìn)入error的方法
- 01-11解決AJAX返回狀態(tài)200沒有調(diào)用success的問題
- 01-11快速解決ajax返回值給外部函數(shù)的問題
- 01-11Ajax實(shí)現(xiàn)動(dòng)態(tài)顯示并操作表信息的方法
- 01-11ajax實(shí)現(xiàn)從后臺(tái)拿數(shù)據(jù)顯示在HTML前端的方法
- 01-11ajax動(dòng)態(tài)查詢數(shù)據(jù)庫數(shù)據(jù)并顯示在前臺(tái)的方法
- 01-11ajax異步讀取后臺(tái)傳遞回的下拉選項(xiàng)的值方法


閱讀排行
本欄相關(guān)
- 01-11layui的checbox在Ajax局部刷新下的設(shè)置方
- 01-11ajax請求后臺(tái)得到j(luò)son數(shù)據(jù)后動(dòng)態(tài)生成樹
- 01-11ajax獲得json對象數(shù)組 循環(huán)輸出數(shù)據(jù)的
- 01-11解決ajax請求后臺(tái),有時(shí)收不到返回值的
- 01-11詳談ajax返回?cái)?shù)據(jù)成功 卻進(jìn)入error的方
- 01-11解決AJAX返回狀態(tài)200沒有調(diào)用success的問
- 01-11快速解決ajax返回值給外部函數(shù)的問題
- 01-11Ajax實(shí)現(xiàn)動(dòng)態(tài)顯示并操作表信息的方法
- 01-11ajax實(shí)現(xiàn)從后臺(tái)拿數(shù)據(jù)顯示在HTML前端的
- 01-11ajax動(dòng)態(tài)查詢數(shù)據(jù)庫數(shù)據(jù)并顯示在前臺(tái)
隨機(jī)閱讀
- 08-05dedecms(織夢)副欄目數(shù)量限制代碼修改
- 01-10delphi制作wav文件的方法
- 08-05DEDE織夢data目錄下的sessions文件夾有什
- 01-10使用C語言求解撲克牌的順子及n個(gè)骰子
- 01-10C#中split用法實(shí)例總結(jié)
- 04-02jquery與jsp,用jquery
- 01-11Mac OSX 打開原生自帶讀寫NTFS功能(圖文
- 01-11ajax實(shí)現(xiàn)頁面的局部加載
- 01-10SublimeText編譯C開發(fā)環(huán)境設(shè)置
- 08-05織夢dedecms什么時(shí)候用欄目交叉功能?