var saveData = [];
function Save(){
saveData = [];
var order = 1;
var code = 1;
var parentCode = "0";
var level = 1;
var roots = $('#dept').tree('getRoots');
if(roots.length > 0){
for(var i = 0; i < roots.length; i++){
// alert(roots[i].attributes.name);
var attributes = roots[i].attributes;
var data = GetAttributes(attributes, roots[i].text, code, parentCode, level, order);
saveData.push(data);
GetChildDataList(roots[i], code, level);
code++;
order++;
}
}
// SAVE
var jsonData = JSON.stringify(saveData);
$.post("SaveDept.action", {saveDeptjsonData: jsonData},
function (data) {
alert(data.msg);
if (data.saveResult) {
searchtreedata();
}
});
}
function GetChildDataList(root, parentid, level){
var children = root.children;
if(children == null || children.length <= 0){
return;
} else {
var order = 1;
var childLevel = level + 1;
for(var j = 0; j < children.length; j++){
var attributes = children[j].attributes;
var code = parentid.toString() + order.toString();
var data = GetAttributes(attributes, children[j].text, code, parentid, childLevel, order);
saveData.push(data);
// 递归
GetChildDataList(children[j], code, childLevel);
order++;
}
}
}
function GetAttributes(attributes, text, treeCode, parentTreeCode, level, order){
var data = {};
data.treeCode = treeCode;
data.name = text;
data.parentTreeCode = parentTreeCode;
data.level = level;
data.ord = order;
data.delFlg = 0;
if(attributes != null){
data.orgId = attributes.orgId;
data.createBy = attributes.createBy;
data.createDate = attributes.createDate;
data.updateBy = attributes.updateBy;
data.updateDate = attributes.updateDate;
}
return data;
}
function Save(){
saveData = [];
var order = 1;
var code = 1;
var parentCode = "0";
var level = 1;
var roots = $('#dept').tree('getRoots');
if(roots.length > 0){
for(var i = 0; i < roots.length; i++){
// alert(roots[i].attributes.name);
var attributes = roots[i].attributes;
var data = GetAttributes(attributes, roots[i].text, code, parentCode, level, order);
saveData.push(data);
GetChildDataList(roots[i], code, level);
code++;
order++;
}
}
// SAVE
var jsonData = JSON.stringify(saveData);
$.post("SaveDept.action", {saveDeptjsonData: jsonData},
function (data) {
alert(data.msg);
if (data.saveResult) {
searchtreedata();
}
});
}
function GetChildDataList(root, parentid, level){
var children = root.children;
if(children == null || children.length <= 0){
return;
} else {
var order = 1;
var childLevel = level + 1;
for(var j = 0; j < children.length; j++){
var attributes = children[j].attributes;
var code = parentid.toString() + order.toString();
var data = GetAttributes(attributes, children[j].text, code, parentid, childLevel, order);
saveData.push(data);
// 递归
GetChildDataList(children[j], code, childLevel);
order++;
}
}
}
function GetAttributes(attributes, text, treeCode, parentTreeCode, level, order){
var data = {};
data.treeCode = treeCode;
data.name = text;
data.parentTreeCode = parentTreeCode;
data.level = level;
data.ord = order;
data.delFlg = 0;
if(attributes != null){
data.orgId = attributes.orgId;
data.createBy = attributes.createBy;
data.createDate = attributes.createDate;
data.updateBy = attributes.updateBy;
data.updateDate = attributes.updateDate;
}
return data;
}
这篇博客介绍了如何使用easyUI库处理递归树结构的数据,通过遍历树节点并递归获取子节点信息,将树形结构转换为JSON字符串,最终实现数据的保存。主要涉及函数包括Save、GetChildDataList和GetAttributes,用于收集树节点的属性和构建数据结构。
1376

被折叠的 条评论
为什么被折叠?



