用Angular如何制作树形二级表格,代码是什么
Admin 2022-06-23 群英技术资讯 864 次浏览
这篇文章将为大家详细讲解有关“用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表格数据的格式类似如下(你们自己写个模拟数据吧):

(2)初始化当前的点击索引变量currentClickOpenIndex 为-1
(3)是展开收起箭头的点击事件:
clickShowChildList = (i,item)=>{
console.log(i,this.currentClickOpenIndex)
if(this.currentClickOpenIndex==i){
this.currentClickOpenIndex = -1
}else{
this.currentClickOpenIndex = i
}
}
然后就完成了……
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:mmqy2019@163.com进行举报,并提供相关证据,查实之后,将立刻删除涉嫌侵权内容。
猜你喜欢
这篇文章主要为大家详细介绍了js实现放大镜效果的思路与代码,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
本文主要介绍了react hooks组件间的传值方式(使用ts),文中通过示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
这篇文章主要为大家详细介绍了小程序实现滑动块,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
本篇文章给大家带来了关于JavaScript中闭包的相关知识,其中包括从堆栈的角度看待闭包、闭包的共享变量问题等相关问题,希望对大家有帮助。
目录mockjs配置和使用方式需求步骤mock使用及mock无侵入的解决什么是mock?为什么要用到mock?如何使用mock?mock无侵入式配置mockjs配置和使用方式需求在前后端分离的开发中,需要前后端同时开发,但是在后端完成前,暂时是没有数据返回给前端使用的,如果先写静态后面再改,就有重复工作的内耗存在。所以
成为群英会员,开启智能安全云计算之旅
立即注册关注或联系群英网络
7x24小时售前:400-678-4567
7x24小时售后:0668-2555666
24小时QQ客服
群英微信公众号
CNNIC域名投诉举报处理平台
服务电话:010-58813000
服务邮箱:service@cnnic.cn
投诉与建议:0668-2555555
Copyright © QY Network Company Ltd. All Rights Reserved. 2003-2020 群英 版权所有
增值电信经营许可证 : B1.B2-20140078 粤ICP备09006778号 域名注册商资质 粤 D3.1-20240008