您好,登錄后才能下訂單哦!
一、顯示ztree 的節(jié)點(diǎn)
1,前臺(tái)轉(zhuǎn)換顯示 :
<div>
<ul id="tree" class="ztree"></ul>
</div>
通過jquery ajax 獲得節(jié)點(diǎn)集合: nodelist
將數(shù)據(jù)轉(zhuǎn)換成指定格式:
var treeNodes = [];
for(var i = 0; i < nodelist.length; i++){
treeNodes.push({id:nodelist[i].bm, parentId:nodelist[i].sjbm, name:nodelist[i].mc,open: ((nodelist[i].sjbm=='0000000') ? true : false),
tag:result[i]});
}
$.fn.zTree.init($("#tree"),selectionSetting, treeNodes);(selectionSetting 的定義省略)
2,后臺(tái)轉(zhuǎn)換顯示:
代碼:
/**
* 將科目數(shù)據(jù)轉(zhuǎn)化成json格式的數(shù)據(jù)用于樹控件
*/
public String getsubjectAll() {
JSONArray jsonArr = new JSONArray();
try {
List<HdzxKm> subjects = subjectDao.getSubjectAll();
for (HdzxKm subject : subjects) {
JSONObject json = new JSONObject();
json.put("id", subject.getBm());
json.put("name", subject.getMc());
if(如果是父級(jí)){
json.put("open", false);
}
json.put("parentId", subject.getSjbm());
jsonArr.add(json);
}
} catch (Exception e) {
e.printStackTrace();
}
return jsonArr.toString();
}
前臺(tái)獲得該方法返回的數(shù)據(jù),就不用轉(zhuǎn)換直接:
$.fn.zTree.init($("#tree"),selectionSetting, treeNodes);(selectionSetting 的定義省略)
treeNodes 為后臺(tái)返回的數(shù)據(jù)
二、根據(jù)節(jié)點(diǎn)的id選中指定節(jié)點(diǎn)
var treeObj = $.fn.zTree.getZTreeObj("tree");
treeObj.selectNode(treeObj.getNodeByParam("id","000000000000", null));(000000000000:節(jié)點(diǎn)Id的值)
三、自定義修改節(jié)點(diǎn)的名稱(根據(jù)節(jié)點(diǎn)id值)
var treeObj = $.fn.zTree.getZTreeObj("tree");
var node = treeObj.getNodeByParam("id", id的值, null);
node.name="xxxxx";
treeObj.updateNode(node,true);(此處為更新節(jié)點(diǎn)值,此步不能省)
四、新增節(jié)點(diǎn)
var treeObj = $.fn.zTree.getZTreeObj("tree");
var node = treeObj.getNodeByParam("id", xxx, null);
treeObj.addNodes(node, {id :xxx,parentId :xxx,name : xxx});
五、有復(fù)選框是,選中指定節(jié)點(diǎn)
var zTree =$.fn.zTree.getZTreeObj("tree");
var node=zTree.getNodeByParam("id",id值, null);
zTree.checkNode(node);
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。