简体   繁体   English

如何在javascript / Angular4 +中用垂直线显示分层的垂直数据?

[英]How to display hierarchical vertical data with vertical line in javascript/Angular4+?

I have a requirement to show some objects in a hierarchical manner as shown below. 我要求以分层方式显示一些对象,如下所示。 在此处输入图片说明

This hierarchy is fixed and no need of dynamic child node needed. 此层次结构是固定的,不需要动态子节点。

Any css demo code will be helpful. 任何CSS演示代码都将有所帮助。 Thanks. 谢谢。

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 : 这是一些用ulli创建树结构的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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM