Home >Web Front-end >JS Tutorial >Five steps to easily implement zTree usage examples

Five steps to easily implement zTree usage examples

小云云
小云云Original
2017-12-28 11:48:434222browse

This article mainly introduces the five steps to easily implement the use of zTree. It has certain reference value. Interested friends can refer to it. I hope it can help everyone.

1. Import the zTree configuration file


<script type="text/javascript" src="../js/ztree/jquery.ztree.all-3.5.js"></script> 
<link rel="stylesheet" href="../js/ztree/zTreeStyle.css" />

2. Set class="ztree"
## in the required location


#

<p data-options="title:&#39;基础菜单&#39;"> 
   <ul id="baseMenu" class="ztree"></ul> 
</p>

3. Choose to generate a simple zTree format or a standard zTree format according to your needs (only simple zTree format is discussed here) ps: Be careful to write

# in the function after the page is loaded.

##

var setting = { 
  data: { 
    simpleData: { 
      enable: true //支持json格式 
  } 
},

4. Write a tree menu (simple and similar to dTree)


var zNodes = [ //驼峰式命名pId 
  {id:1,pId:0,name:"父节点1"},       
  {id:2,pId:0,name:"父节点2"},           
  {id:11,pId:1,name:"父1子节点1"}, 
  {id:12,pId:1,name:"父1子节点2"}, 
];

5. Spanning tree Shape menu


$.fn.zTree.init($("#baseMenu"), setting, zNodes);

Related recommendations:


Detailed examples of the use of zTree jQuery tree plug-in

Examples to explain how jQuery uses the zTree plug-in to implement drag-and-drop functionality

Sharing the use of the zTree tree plug-in in jQuery

The above is the detailed content of Five steps to easily implement zTree usage examples. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn