基于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 相关文章推荐
Ext.get() 和 Ext.query()组合使用实现最灵活的取元素方式
Sep 26 Javascript
EasyUI中的tree用法介绍
Nov 01 Javascript
js jquery验证银行卡号信息正则学习
Jan 21 Javascript
JS判断两个时间大小的示例代码
Jan 28 Javascript
纯css实现窗户玻璃雨滴逼真效果
Aug 23 Javascript
JS组件系列之Bootstrap table表格组件神器【终结篇】
May 10 Javascript
微信支付 JS API支付接口详解
Jul 11 Javascript
使用vue.js实现checkbox的全选和多个的删除功能
Feb 17 Javascript
Vue2 配置 Axios api 接口调用文件的方法
Nov 13 Javascript
微信小程序实现左右联动的实战记录
Jul 05 Javascript
vue异步axios获取的数据渲染到页面的方法
Aug 09 Javascript
在vue中使用v-bind:class的选项卡方法
Sep 27 Javascript
ajax请求前端跨域问题原因及解决方案
浅谈TypeScript 索引签名的理解
JavaScript 反射学习技巧
Oct 16 #Javascript
JS的深浅复制详细
Oct 16 #Javascript
JS 基本概念详细介绍
Oct 16 #Javascript
AJAX实现指定部分页面刷新效果
AJAX实现省市县三级联动效果
Oct 16 #Javascript
You might like
PHP mail 通过Windows的SMTP发送邮件失败的解决方案
2009/05/27 PHP
彻底杜绝PHP的session cookie错误
2009/08/09 PHP
WordPress自定义时间显示格式
2015/03/27 PHP
PHP设计模式之适配器模式定义与用法详解
2018/04/03 PHP
新浪的图片新闻效果
2007/01/13 Javascript
JavaScript初学者需要了解10个小技巧
2010/08/25 Javascript
jquery获取特定name所有选中的checkbox,支持IE9标准模式
2013/03/18 Javascript
jquery mobile实现拨打电话功能的几种方法
2013/08/05 Javascript
JavaScript中实现PHP的打乱数组函数shuffle实例
2014/10/11 Javascript
使用Jquery实现每日签到功能
2015/04/03 Javascript
JavaScript实现控制打开文件另存为对话框的方法
2015/04/17 Javascript
原生js实现数字字母混合验证码的简单实例
2015/12/10 Javascript
Treegrid的动态加载实例代码
2016/04/29 Javascript
JS实现页面进入和返回定位到具体位置
2016/12/08 Javascript
使用Angular缓存父页面数据的方法
2017/01/03 Javascript
Ionic 2 实现列表滑动删除按钮的方法
2017/01/22 Javascript
React学习笔记之事件处理(二)
2017/07/02 Javascript
在微信小程序里使用watch和computed的方法
2018/08/02 Javascript
微信小程序使用wxParse解析html的方法示例
2019/01/17 Javascript
详解vue挂载到dom上会发生什么
2019/01/20 Javascript
React中this丢失的四种解决方法
2019/03/12 Javascript
[00:39]DOTA2上海特级锦标赛 Liquid战队宣传片
2016/03/04 DOTA
[07:37]DOTA2-DPC中国联赛2月2日Recap集锦
2021/03/11 DOTA
Python编程之多态用法实例详解
2015/05/19 Python
Python实现字典的key和values的交换
2015/08/04 Python
浅析Python基础-流程控制
2016/03/18 Python
python3结合openpyxl库实现excel操作的实例代码
2018/09/11 Python
搞定这套Python爬虫面试题(面试会so easy)
2019/04/03 Python
python创建学生管理系统
2019/11/22 Python
django 模型字段设置默认值代码
2020/07/15 Python
教你怎样写好自我评价
2013/10/05 职场文书
老公爱的承诺书
2014/03/31 职场文书
小学校园广播稿集锦
2014/10/04 职场文书
js实现模拟购物商城案例
2021/05/18 Javascript
mysql的数据压缩性能对比详情
2021/11/07 MySQL
mysql中关键词exists的用法实例详解
2022/06/10 MySQL