微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Angular directive递归实现目录树结构代码实例

整理文档,搜刮出一个Angular directive递归实现目录树结构代码实例代码,稍微整理精简一下做下分享

效果图:

重点:

1. 整棵目录树的实现,通过嵌套完成,主要在于对treeItem.html的递归使用

rush:js;">

<script type="text/ng-template" id="treeItem.html">

<span class="color-indictor" ng-class="{'leaf-node': isLeaf(item),'expand-node': !isLeaf(item) && item.isExpand,'unexpand-node': !isLeaf(item) && !item.isExpand}" ng-click="toggleExpandStatus(item)"&gt;</span>

<span>{{item.name}}</span>

<ul ng-if="!isLeaf(item)" ng-show="item.isExpand"&gt;

  <li ng-repeat="item in item.children" ng-include="'treeItem.html'"&gt;</li>

</ul>

2. 点击展开/关闭目录树

通过ng-show对item.expand进行判断,点击item时切换其expand参数,完成目录树的打开与关闭

3. 源码

rush:js;">

Introduce: Click green block expand the menu tree

Red: Leaf node,can not click

Green: Unexpand node,click to expand menu

Yellow: Expanded node,click to unexpand menu

<script type="text/ng-template" id="treeView.html">

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持编程之家。

原文地址:https://www.jb51.cc/js/39506.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐