基于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 相关文章推荐
基于Jquery的动态添加控件并取值的实现代码
Sep 24 Javascript
jQuery模拟点击A标记示例参考
Apr 17 Javascript
通过AngularJS实现图片上传及缩略图展示示例
Jan 03 Javascript
微信小程序 获取javascript 里的数据
Aug 17 Javascript
vue mint-ui学习笔记之picker的使用
Oct 11 Javascript
JavaScript实现一个带AI的井字棋游戏源码
May 21 Javascript
Vue登录注册并保持登录状态的方法
Aug 17 Javascript
JS实现倒计时图文效果
Nov 17 Javascript
Vue源码之关于vm.$delete()/Vue.use()内部原理详解
May 01 Javascript
vue父组件给子组件的组件传值provide inject的方法
Oct 23 Javascript
Vue组件模板的几种书写形式(3种)
Feb 19 Javascript
vue 限制input只能输入正数的操作
Aug 05 Javascript
ajax请求前端跨域问题原因及解决方案
浅谈TypeScript 索引签名的理解
JavaScript 反射学习技巧
Oct 16 #Javascript
JS的深浅复制详细
Oct 16 #Javascript
JS 基本概念详细介绍
Oct 16 #Javascript
AJAX实现指定部分页面刷新效果
AJAX实现省市县三级联动效果
Oct 16 #Javascript
You might like
判“新”函数:得到今天与明天的秒数
2006/10/09 PHP
隐藏X-Space个人空间下方版权方法隐藏X-Space个人空间标题隐藏X-Space个人空间管理版权方法
2007/02/22 PHP
android上传图片到PHP的过程详解
2015/08/03 PHP
PC端微信扫码支付成功之后自动跳转php版代码
2017/07/07 PHP
PHPExcel 修改已存在Excel的方法
2018/05/03 PHP
Yii框架使用PHPExcel导出Excel文件的方法分析【改进版】
2019/07/24 PHP
Jquery submit()无法提交问题
2013/04/21 Javascript
js 获取、清空input type=&quot;file&quot;的值示例代码
2014/02/19 Javascript
javascript中传统事件与现代事件
2015/06/23 Javascript
JavaScript中利用Array和Object实现Map的方法
2015/07/27 Javascript
javascript html5移动端轻松实现文件上传
2020/03/27 Javascript
BootStrap点击下拉菜单项后显示一个新的输入框实现代码
2016/05/16 Javascript
基于css3新属性transform及原生js实现鼠标拖动3d立方体旋转
2016/06/12 Javascript
Bootstrap弹出框(Popover)被挤压的问题小结
2017/07/11 Javascript
Python strip lstrip rstrip使用方法
2008/09/06 Python
python通过线程实现定时器timer的方法
2015/03/16 Python
python实现mysql的单引号字符串过滤方法
2015/11/14 Python
Python中使用Queue和Condition进行线程同步的方法
2016/01/19 Python
Pycharm学习教程(7)虚拟机VM的配置教程
2017/05/04 Python
django rest framework 数据的查找、过滤、排序的示例
2018/06/25 Python
Python中如何使用if语句处理列表实例代码
2019/02/24 Python
Python2与Python3的区别实例总结
2019/04/17 Python
python实现大学人员管理系统
2019/10/25 Python
tensorflow实现打印ckpt模型保存下的变量名称及变量值
2020/01/04 Python
python各层级目录下import方法代码实例
2020/01/20 Python
零基础学Python之前需要学c语言吗
2020/07/21 Python
html5本地存储之localstorage 、本地数据库、sessionStorage简单使用示例
2014/05/08 HTML / CSS
SK-II神仙水美国官网:SK-II美国
2020/02/25 全球购物
智能家居、吸尘器、滑板车、电动自行车网上购物:Geekmaxi
2021/01/18 全球购物
化工专业推荐信范文
2013/11/28 职场文书
中班教师个人总结
2015/02/05 职场文书
成品仓管员岗位职责
2015/04/01 职场文书
保姆聘用合同
2015/09/21 职场文书
《颐和园》教学反思
2016/02/19 职场文书
分家协议书范本
2016/03/22 职场文书
Oracle 死锁的检测查询及处理
2021/09/25 Oracle