ajax请求后台得到json数据后动态生成树形下拉框
2017-01-15 15:03
525 查看
<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,
//选择树节点触发事件
onSelect : function(node) {
n = node;
//返回树对象
var tree = $(this).tree;
//选中的节点是否为叶子节点,如果不是叶子节点,清除选中
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>
转成json格式后,传到jsp页面,在前台页面中处理json数据,动态生成下拉树。
<script>
$(function(){
$.ajax({
url:"departmentAction_getAllDep.action",
type:"post",
success:function(result){
//console.log(result);
$("#cc").combotree('loadData',b1(result));
}
});
$("#cc").combotree({
animate:true,
//选择树节点触发事件
onSelect : function(node) {
n = node;
//返回树对象
var tree = $(this).tree;
//选中的节点是否为叶子节点,如果不是叶子节点,清除选中
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>
转成json格式后,传到jsp页面,在前台页面中处理json数据,动态生成下拉树。
相关文章推荐
- ajax请求后台得到json数据后动态生成树形下拉框的方法
- Ajax获取php返回json数据动态生成select下拉框
- Ajax获取php返回json数据动态生成select下拉框的实例
- 原生js,jquery通过ajax获得后台json数据动态新增页面元素
- 发送ajax请求无刷新生成表格的方法(处理json数据)...
- easyui 下拉框点击ajax后台json数据 实时刷新
- JS-利用ajax获取json数据,并传入页面生成动态tab
- asp.net+FusionCharts+jQuery(ajax)后台请求数据生成图表
- ajax请求后台,后台有数据,前台得不到数据(json)
- ajax请求后台,返回json格式数据,模板!
- 通过ajax ------后台为前台动态生成html标签,并将后台数据传输到前台(传参)
- jquery-ajax请求后台数据转换json显示在select下拉列表&&jquery获取下拉列表的值和显示内容的方法
- 运用jQuery通过AJAX向后台请求拼装json数据格式,并初始化目录树TreeView
- jquery的ajax请求处理以及处理后台java传的json数据
- php ajax从后台返回json数据,并把数据赋值给自动生成HTML标签
- 后台传JSON,前台动态生成一个下拉框
- jquery-ajax请求后台数据转换json显示在select下拉列表
- 通过Ajax请求后台数据,返回JSONArray(JsonObject),页面(Jquery)以table的形式展示
- asp.net+FusionCharts+jQuery(ajax)后台请求数据生成图表
- 采用ajax请求返回得到json数据,取出具体项却为undefined