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">

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

相关文章

前言 做过web项目开发的人对layer弹层组件肯定不陌生,作为l...
前言 前端表单校验是过滤无效数据、假数据、有毒数据的第一步...
前言 图片上传是web项目常见的需求,我基于之前的博客的代码...
前言 导出Excel文件这个功能,通常都是在后端实现返回前端一...
前言 众所周知,js是单线程的,从上往下,从左往右依次执行,...
前言 项目开发中,我们可能会碰到这样的需求:select标签,禁...