基于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 相关文章推荐
jQueryPad 实用的jQuery测试工具(支持IE,chrome,FF)
May 22 Javascript
js使用post 方式打开新窗口
Feb 26 Javascript
javascript随机抽取0-100之间不重复的10个数
Feb 25 Javascript
javascript实现标签切换代码示例
May 22 Javascript
jquery仿京东商品放大浏览页面
Jun 06 jQuery
使用JavaScript实现点击循环切换图片效果
Sep 03 Javascript
Node.js使用Express.Router的方法
Nov 14 Javascript
VScode格式化ESlint方法(最全最好用方法)
Sep 10 Javascript
Vue学习笔记之计算属性与侦听器用法
Dec 07 Javascript
node创建Vue项目步骤详解
Mar 06 Javascript
JS+canvas五子棋人机对战实现步骤详解
Jun 04 Javascript
在Vuex中Mutations修改状态操作
Jul 24 Javascript
ajax请求前端跨域问题原因及解决方案
浅谈TypeScript 索引签名的理解
JavaScript 反射学习技巧
Oct 16 #Javascript
JS的深浅复制详细
Oct 16 #Javascript
JS 基本概念详细介绍
Oct 16 #Javascript
AJAX实现指定部分页面刷新效果
AJAX实现省市县三级联动效果
Oct 16 #Javascript
You might like
php通过COM类调用组件的实现代码
2012/01/11 PHP
php中的一些数组排序方法分享
2012/07/20 PHP
php、mysql查询当天,查询本周,查询本月的数据实例(字段是时间戳)
2017/02/04 PHP
利用PHPExcel实现Excel文件的写入和读取
2017/04/26 PHP
php empty 函数判断结果为空但实际值却为非空的原因解析
2018/05/28 PHP
PHP二维索引数组的遍历实例分析【2种方式】
2019/06/24 PHP
JScript 脚本实现文件下载 一般用于下载木马
2009/10/29 Javascript
jquery多行滚动/向左或向上滚动/响应鼠标实现思路及代码
2013/01/23 Javascript
nodejs之请求路由概述
2014/07/05 NodeJs
node.js中的console.timeEnd方法使用说明
2014/12/09 Javascript
jQuery判断对象是否存在的方法
2015/02/05 Javascript
JS+CSS实现Li列表隔行换色效果的方法
2015/02/16 Javascript
JavaScript实现99乘法表及隔行变色实例代码
2016/02/24 Javascript
jQuery+ajax实现实用的点赞插件代码
2016/07/06 Javascript
jQuery Ajax前后端使用JSON进行交互示例
2017/03/17 Javascript
详解用node编写自己的cli工具
2017/05/23 Javascript
详解在vue-cli中使用路由
2017/09/25 Javascript
浅谈Angular6的服务和依赖注入
2018/06/27 Javascript
ES6中Set和Map数据结构,Map与其它数据结构互相转换操作实例详解
2019/02/28 Javascript
Cordova(ionic)项目实现双击返回键退出应用
2019/09/17 Javascript
js实现小时钟效果
2020/03/25 Javascript
总结网络IO模型与select模型的Python实例讲解
2016/06/27 Python
windows下安装python的C扩展编译环境(解决Unable to find vcvarsall.bat)
2018/02/21 Python
Python遍历文件夹 处理json文件的方法
2019/01/22 Python
一步步教你用python的scrapy编写一个爬虫
2019/04/17 Python
Python上下文管理器类和上下文管理器装饰器contextmanager用法实例分析
2019/11/07 Python
python实现的Iou与Giou代码
2020/01/18 Python
python传到前端的数据,双引号被转义的问题
2020/04/03 Python
python语言中有算法吗
2020/06/16 Python
HTML5 在canvas中绘制文本附效果图
2014/06/23 HTML / CSS
阿提哈德航空官方网站:Etihad Airways
2017/01/06 全球购物
单位委托书范本
2014/04/04 职场文书
运动会闭幕式通讯稿
2015/07/18 职场文书
《少年闰土》教学反思
2016/02/18 职场文书
你对自己的信用报告有过了解吗?
2019/07/09 职场文书
pt-archiver 主键自增
2022/04/26 MySQL