基于angular实现树形二级表格


Posted in Javascript onOctober 16, 2021

先看效果:

基于angular实现树形二级表格

代码:

1、html

<div class="userContent_content">
    <div>
      <table>
        <tr>
          <td>节点名称</td>
          <td>节点管理IP</td>
          <td>节点登录名</td> 
          <td>节点登录密码</td> 
        </tr>
        //使用ng-container作为空标签用于辅助放置for或者if事件,它在审查元素中是找不到的
        <ng-container *ngFor="let item of currentTotalList,let i = index">
          <tr>
            <td style="color: #04AEB4;cursor: pointer;" class="img">
              <div>
                <div>{{item.name}}</div>
                <div>
        //下面是箭头的图片,是展开和收起箭头的切换,通过判断当前点击索引与列表索引是否相等,相等则展开,否则收起
                  <img (click)="clickShowChildList(i,item.name)"
                    [attr.src]="i == currentClickOpenIndex?'../../assets/resource/img/bottom.png':'../../assets/resource/img/right.png'">
                </div>
              </div>
            </td>
            <td>{{item.ip}}</td>
            <td>{{item.username}}</td>
            <td>{{item.password}}</td>
          </tr>
        //再次使用ng-container标签嵌套表格的子级
          <ng-container *ngFor="let childItem of item.nodeList, let j = index">
        //由于在同一个标签内,for循环和if判断不能同时共存,因此我们的隐藏事件if放置tr标签内,通过判断当前点击的索引与列表索引是否一致,相等则收起,不等则显示的功能。
 
            <tr *ngIf="i == currentClickOpenIndex">
              <td style="color: #04AEB4;cursor: pointer;" class="img">
                <div>
                  <div>
                    {{childItem.masterIp}}</div>
                </div>
              </td>
              <td>{{childItem.ip}}</td>
              <td>{{childItem.username}}</td>
              <td>{{childItem.password}}</td>
            </tr>
          </ng-container>
        </ng-container>
 
      </table>
    </div>
    
  </div>

2、less

.userContent_content{
        width: 100%;
        height: calc(~"100% - 60px");
        overflow: auto;
        >div:nth-child(1){
          >table{
            width: 100%;
            tr{
              td{
                width: 25%;
                text-align: center;
                font-size: 14px;
                color: #fff;
                padding: 16px 0px;
                box-shadow: 0 1px #333;
              }
            }
            .img {
              >div {
                width: 100%;
                display: flex;
                position: relative;
  
                >div:nth-child(1) {
                  width: 85%;
                  white-space: nowrap;
                  text-overflow: ellipsis;
                  -o-text-overflow: ellipsis;
                  overflow: hidden;
                  margin: 0 auto;
  
                }
              }
  
              img {
                height: 10px !important;
                width: 10px !important;
                margin-left: 0 !important;
                position: absolute;
                right: 0;
                top: 3px;
              }
            }
          }
        }
  
        >div:nth-child(2){
          height: 80px;
          width: 90%;
          display: flex;
          align-items: center;
          margin: 0 auto;
          justify-content: flex-end;
          #page{
            display: table;
          }
        }
      }

3、js

(1)currentTotalList表格数据的格式类似如下(你们自己写个模拟数据吧):

基于angular实现树形二级表格

(2)初始化当前的点击索引变量currentClickOpenIndex 为-1

(3)是展开收起箭头的点击事件:

clickShowChildList = (i,item)=>{
    console.log(i,this.currentClickOpenIndex)
    if(this.currentClickOpenIndex==i){
      this.currentClickOpenIndex = -1
    }else{
      this.currentClickOpenIndex = i
    }
  }

然后就完成了……

到此这篇关于基于angular实现树形二级表格的文章就介绍到这了,更多相关angular树形二级表格内容请搜索三水点靠木以前的文章或继续浏览下面的相关文章希望大家以后多多支持三水点靠木!


Tags in this post...

Javascript 相关文章推荐
js对table的td进行相同内容合并示例详解
Dec 27 Javascript
JS中类或对象的定义说明
Mar 10 Javascript
Jquery 在页面加载后执行的几种方式
Mar 14 Javascript
JS中实现函数return多个返回值的实例
Feb 21 Javascript
vue组件如何被其他项目引用
Apr 13 Javascript
深究AngularJS中$sce的使用
Jun 12 Javascript
jQuery实现定时隐藏对话框的方法分析
Feb 12 jQuery
详解使用React制作一个模态框
Mar 14 Javascript
原生js实现商品筛选功能
Oct 28 Javascript
使用typescript改造koa开发框架的实现
Feb 04 Javascript
Vue实现简易计算器
Feb 25 Javascript
JavaScript 中的执行上下文和执行栈实例讲解
Feb 25 Javascript
ajax请求前端跨域问题原因及解决方案
浅谈TypeScript 索引签名的理解
JavaScript 反射学习技巧
Oct 16 #Javascript
JS的深浅复制详细
Oct 16 #Javascript
JS 基本概念详细介绍
Oct 16 #Javascript
AJAX实现指定部分页面刷新效果
AJAX实现省市县三级联动效果
Oct 16 #Javascript
You might like
PHP和MySql中32位和64位的整形范围是多少
2016/02/18 PHP
Yii2.0 RESTful API 基础配置教程详解
2018/12/26 PHP
xtree.js 代码
2007/03/13 Javascript
Javascript学习笔记-详解in运算符
2011/09/13 Javascript
jquery延迟加载外部js实现代码
2013/01/11 Javascript
js统计录入文本框中字符的个数并加以限制不超过多少
2014/05/23 Javascript
Jquery网页内滑动缓冲导航的实现代码
2015/04/05 Javascript
JS实现的文字与图片定时切换效果代码
2015/10/06 Javascript
JS模拟按钮点击功能的方法
2015/12/22 Javascript
JavaScipt中栈的实现方法
2016/02/17 Javascript
javascript中利用柯里化函数实现bind方法【推荐】
2016/04/29 Javascript
fullCalendar中文API官方文档
2017/02/07 Javascript
html2canvas属性和使用方法以及如何使用html2canvas将HTML内容写入Canvas生成图片
2020/01/12 Javascript
[01:01:13]2018DOTA2亚洲邀请赛 4.5 淘汰赛 Mineski vs VG 第三场
2018/04/06 DOTA
pyramid配置session的方法教程
2013/11/27 Python
Python中集合的内建函数和内建方法学习教程
2015/08/19 Python
python 性能优化方法小结
2017/03/31 Python
python中装饰器级连的使用方法示例
2017/09/29 Python
Python实现的rsa加密算法详解
2018/01/24 Python
python selenium 查找隐藏元素 自动播放视频功能
2019/07/24 Python
python的mysql数据库建立表与插入数据操作示例
2019/09/30 Python
python GUI库图形界面开发之PyQt5浏览器控件QWebEngineView详细使用方法
2020/02/26 Python
python实现TCP文件传输
2020/03/20 Python
Python-opencv实现红绿两色识别操作
2020/06/04 Python
在python中对于bool布尔值的取反操作
2020/12/11 Python
python字典与json转换的方法总结
2020/12/28 Python
Jupyter安装拓展nbextensions及解决官网下载慢的问题
2021/03/03 Python
领先的英国注册在线药房 :Simply Meds Online
2019/03/28 全球购物
客服部工作职责范本
2014/02/14 职场文书
审计专业自荐信范文
2014/04/21 职场文书
创建绿色社区汇报材料
2014/08/22 职场文书
教师批评与自我批评范文
2014/10/15 职场文书
2014年度思想工作总结
2014/11/27 职场文书
Mysql文件存储图文详解
2021/06/01 MySQL
详解nginx进程锁的实现
2021/06/14 Servers
进阶篇之linux环境下安装MySQL数据库
2022/04/09 MySQL