- 注册时间
- 2014-1-14
- 最后登录
- 2014-1-15
- 阅读权限
- 10
- 积分
- 18
- 精华
- 0
- 帖子
- 6
|
//新增节点
function onAddNode(e) {
var tree = mini.get("tree1");
var node = tree.getSelectedNode();
var newNode = {name: "新建分类" };
tree.addNode(newNode, "add", node);
saveData();
}
//保存节点
function saveData() {
var tree = mini.get("tree1");
var data = tree.getData();
var json = mini.encode(data);
var msgid = mini.loading("数据保存中,请稍后......", "保存数据");
jQuery.ajax({
url: "data/TreeService.jsp?method=SaveTree",
data: { data: json },
type: "post",
success: function (text) {
mini.hideMessageBox(msgid);
window.location.reload();
},
error: function (jqXHR, textStatus, errorThrown) {
alert(jqXHR.responseText);
}
});
}
public void SaveTree(HttpServletRequest request, HttpServletResponse response)throws Exception
{
String dataJSON = request.getParameter("data");
ArrayList tree = (ArrayList)Admin.dao.JSON.Decode(dataJSON);
//树形转换为列表
ArrayList list = TreeUtil.ToList(tree, "-1", "children", "id", "pid");
//生成id和num
for(int i = 0,l = list.size();i<l;i++){
HashMap node = (HashMap)list.get(i);
if(node.get("id") == null || node.get("id").toString().equals("")){
String UID = UUID.randomUUID().toString();
node.put("id",UID);
}
node.put("num",i);
}
//生成pid
list = TreeUtil.ToList(tree, "-1", "children", "id", "pid");
// Add/Update/Move Node
for(int i=0,l=list.size();i<l;i++){
HashMap node = (HashMap)list.get(i);
String state = node.get("_state") == null ? "" : node.get("_state").toString();
if(state.equals("added"))
{
new Admin.dao.TestDB().InsertClass(node);
}else{
new Admin.dao.TestDB().UpdateClass(node);
}
}
}
|
|