js顯示及操作樹節點
阿新 • • 發佈:2019-01-30
var setting = {
edit: {
enable: true
},
check: {
enable: false
},
data: {
simpleData: {
enable: true
}
},
callback: {
onClick: treeClick
}
};
var zs ="${menujson}";//獲取後臺傳遞的json字串
var zNodes=eval("("+zs+")");//將json格式的字串進行解析
$(document).ready(function(){
$.fn.zTree.init($("#treeDemo"), setting, zNodes);//初始化樹結構
page.zTree = $.fn.zTree.getZTreeObj("treeDemo");
page.menuCode='${menuCode}';
var node = page.zTree.getNodeByParam("id", page.menuCode);//選中的樹節點的回顯
page.zTree.selectNode(node);
});
//點選樹型選單節點
function treeClick(event, treeId, treeNode, clickFlag) {
page.menuCode = treeNode.id;
window.location.href="${ctx }/menu/list?menuCode="+page.menuCode;
edit: {
enable: true
},
check: {
enable: false
},
data: {
simpleData: {
enable: true
}
},
callback: {
onClick: treeClick
}
};
var zs ="${menujson}";//獲取後臺傳遞的json字串
var zNodes=eval("("+zs+")");//將json格式的字串進行解析
$(document).ready(function(){
$.fn.zTree.init($("#treeDemo"), setting, zNodes);//初始化樹結構
page.zTree = $.fn.zTree.getZTreeObj("treeDemo");
page.menuCode='${menuCode}';
var node = page.zTree.getNodeByParam("id", page.menuCode);//選中的樹節點的回顯
page.zTree.selectNode(node);
});
//點選樹型選單節點
function treeClick(event, treeId, treeNode, clickFlag) {
page.menuCode = treeNode.id;
window.location.href="${ctx }/menu/list?menuCode="+page.menuCode;
}
//後臺傳遞的json格式的字串
public String menuList(){
List result = null;
StringBuffer json = new StringBuffer("[");
result = menuMapper.getMenulistByAll();//查資料庫獲取所有的選單
Iterator iter=result.iterator();
while(iter.hasNext()){
Menu menu = (Menu) iter.next();
json.append("{ menuId:'"+menu.getId()+"',id:'"+menu.getCode()+"', pId:'"+menu.getFcode()+"',name:'"+menu.getName()+"', open:false},");
}
if(json.length()>1){
json.delete(json.length()-1, json.length());
}
json.append("]");
return json.toString();
}