前端之插件-ztree

来源:互联网 发布:linux nginx 域名绑定 编辑:程序博客网 时间:2024/06/04 23:19

zTree添加自定义属性

1.定义时直接添加属性var zNodes =[     { id:1, pId:0, name:"pNode 1", open:true, attr:"id1"},     { id:11, pId:1, name:"pNode 11", attr:"id11"},     { id:111, pId:11, name:"leaf node 111", attr:"id111"},     { id:112, pId:11, name:"leaf node 112", attr:"id112"},     { id:12, pId:1, name:"pNode 12", attr:"id12"},     { id:2, pId:0, name:"pNode 2", attr:"id2"},     { id:21, pId:2, name:"pNode 21", open:true, attr:"id21"}  ];  2.通过json转化到js对象来添加属性var zTree = $.fn.zTree.getZTreeObj("treeDemo");  var nodes = zTree.getSelectedNodes();  nodes.sort(function compare(a, b) { return a.id - b.id; });  var v = "";  for (var i = 0, l = nodes.length; i < l; i++) {          v += nodes[i].attr+ ",";      }  if (v.length > 0) v = v.substring(0, v.length - 1);  alert("The attr value of selected nodes:"+v.toString());  
原创粉丝点击