一、顯示ztree 的節點
成都創新互聯公司-專業網站定制、快速模板網站建設、高性價比明水網站開發、企業建站全套包干低至880元,成熟完善的模板庫,直接使用。一站式明水網站制作公司更省心,省錢,快速模板網站建設找我們,業務覆蓋明水地區。費用合理售后完善,十載實體公司更值得信賴。
1,前臺轉換顯示 :
<div>
<ul id="tree" class="ztree"></ul>
</div>
通過jquery ajax 獲得節點集合: nodelist
將數據轉換成指定格式:
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,后臺轉換顯示:
代碼:
/**
* 將科目數據轉化成json格式的數據用于樹控件
*/
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(如果是父級){
json.put("open", false);
}
json.put("parentId", subject.getSjbm());
jsonArr.add(json);
}
} catch (Exception e) {
e.printStackTrace();
}
return jsonArr.toString();
}
前臺獲得該方法返回的數據,就不用轉換直接:
$.fn.zTree.init($("#tree"),selectionSetting, treeNodes);(selectionSetting 的定義省略)
treeNodes 為后臺返回的數據
二、根據節點的id選中指定節點
var treeObj = $.fn.zTree.getZTreeObj("tree");
treeObj.selectNode(treeObj.getNodeByParam("id","000000000000", null));(000000000000:節點Id的值)
三、自定義修改節點的名稱(根據節點id值)
var treeObj = $.fn.zTree.getZTreeObj("tree");
var node = treeObj.getNodeByParam("id", id的值, null);
node.name="xxxxx";
treeObj.updateNode(node,true);(此處為更新節點值,此步不能省)
四、新增節點
var treeObj = $.fn.zTree.getZTreeObj("tree");
var node = treeObj.getNodeByParam("id", xxx, null);
treeObj.addNodes(node, {id :xxx,parentId :xxx,name : xxx});
五、有復選框是,選中指定節點
var zTree =$.fn.zTree.getZTreeObj("tree");
var node=zTree.getNodeByParam("id",id值, null);
zTree.checkNode(node);
名稱欄目:jquery ztree的一些簡單操作
鏈接分享:http://vcdvsql.cn/article0/jhieoo.html
成都網站建設公司_創新互聯,為您提供面包屑導航、自適應網站、網站內鏈、移動網站建設、微信公眾號、企業建站
聲明:本網站發布的內容(圖片、視頻和文字)以用戶投稿、用戶轉載內容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網站立場,如需處理請聯系客服。電話:028-86922220;郵箱:631063699@qq.com。內容未經允許不得轉載,或轉載時需注明來源: 創新互聯