Home > Web Front-end > JS Tutorial > body text

zTree asynchronously loads and expands the first level node method implementation

小云云
Release: 2017-12-29 11:16:08
Original
2702 people have browsed it

This article mainly introduces the implementation method of zTree asynchronous loading and expansion of first-level nodes. Friends who need it can refer to it. I hope it can help everyone.

Add the onAsyncSuccess:onAsyncSuccess callback function to the callback in the setting, and then implement the callback function

var isFirst = true;
function onAsyncSuccess(event, treeId) {
  if (isFirst) {
      //获得树形图对象
      var zTree = $.fn.zTree.getZTreeObj("treeDemo");
      //获取根节点个数,getNodes获取的是根节点的集合
      var nodeList = zTree.getNodes();
      //展开第一个根节点
      zTree.expandNode(nodeList[0], true);
      //当再次点击节点时条件不符合,直接跳出方法
      isFirst= false;
  }
}
Copy after login

Let me share with you how zTree obtains the number of next-level child nodes of the current node. .

Use the zTree plug-in to implement the need to obtain the number of child nodes of the currently clicked parent node in the tree diagram. Use treeNode.children to obtain the child node data collection, and use the length method to obtain the collection length.

You can call it by passing in the treeNode of the current node.

/*查找当前节点下一级的子节点数*/
function findNodes(treeNode)
{
  var count;
  /*判断是不是父节点,是的话找出子节点个数,加一是为了给新增节点*/
  if(treeNode.isParent) {
    count = treeNode.children.length + 1 ;
  } else {
    /*如果不是父节点,说明没有子节点,设置为1*/
    count = 1;
  }
  return count;
}
Copy after login

Related recommendations:

zTree loads all nodes asynchronously

jquery zTree asynchronous loading simple example sharing_jquery

jquery zTree asynchronous loading, fuzzy search simple example sharing_jquery

The above is the detailed content of zTree asynchronously loads and expands the first level node method implementation. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!