[英]How to display hierarchical vertical data with vertical line in javascript/Angular4+?
Create some Item
component and recursively call it on it's template: 创建一些
Item
组件,然后在其模板上递归调用它:
@Component({
selector: 'my-item',
template: `
<div class="main" *ngFor="let itm of childs">
<div class='item'>{{itm.name}} </div>
<my-item [childs] = "itm.childs"> </my-item>
</div>
`,
styleUrls: ['./my-item.component.css']
})
export class ItemComponent {
@Input() childs: SomeClass[];
ngOnInit(){
}
}
Simple class: 简单类:
export class SomeClass {
name: string;
childs: SomeClass[] = [];
constructor(name: string, childs?: SomeClass[]) {
this.name = name;
this.childs = childs;
}
}
app.component.html: app.component.html:
<my-item [childs]="[parent]"> </my-item>
my-item.component.css: my-item.component.css:
:host{
display: flex;
width: 100%;
justify-content: space-between;
text-align: center;
}
.main{
min-width: 100px;
margin: 15px 0;
}
StackBlitz EXAMPLE StackBlitz示例
Result: 结果:
Here is some CSS to create a tree strcture with ul
and li
: 这是一些用
ul
和li
创建树结构的CSS:
ul.tree, ul.tree ul { list-style: none; margin: 0; padding: 0; } ul.tree ul { margin-left: 10px; } ul.tree li { margin: 0; padding: 0 7px; line-height: 20px; color: #369; font-weight: bold; border-left:1px solid rgb(100,100,100); } ul.tree li:last-child { border-left:none; } ul.tree li:before { position:relative; top:-0.3em; height:1em; width:12px; color:white; border-bottom:1px solid rgb(100,100,100); content:""; display:inline-block; left:-7px; } ul.tree li:last-child:before { border-left:1px solid rgb(100,100,100); }
<ul class="tree"> <li>2 Hosts </li> <li>10 objects <ul> <li>4 Type a </li> <li>4 Type b </li> <li>4 Type c </li> </ul> </li> </ul>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.