简体   繁体   English

分层缩进

[英]Hierarchical Indentation

Not sure of the best way to describe it but a picture should work.不确定描述它的最佳方式,但图片应该有效。 I have data structured as a tree and I'd like to display it with various levels of indentation.我将数据结构为一棵树,我想用不同级别的缩进来显示它。

[1                        ]
    [1a                   ]
        [1ai              ]
    [1b                   ]
[2                        ]
[3                        ]
    [3a                   ]

etc等等

The key being indenting the left and lining up on the right.关键是向左缩进并在右侧对齐。

Programatically increasing the padding-left of each element works for the first half, but might not be the correct approach.以编程方式增加每个元素的 padding-left 适用于前半部分,但可能不是正确的方法。

I'm using a recursive angular component, though I didn't mention angular originally b/ci don't think its necessarily relevant to the solution.我正在使用递归角度组件,虽然我没有提到 angular 最初 b/ci 认为它不一定与解决方案相关。

ts ts

export class HierarchicalJobNodeComponent{

  @Input() job: JobHierarchical;

  @Input() depth: number;


  pxDepth(): string {
    return this.depth + "px";
  }

  style(): Object {
    return  { 'margin-left': this.depth + "px", 'width':'100%' };
  }
}

html html

<div class="node container" [ngStyle]="style()">
  <div class="row">
    <div class="col-sm-3">{{job.job_JobId}}</div>
    <div class="col-sm-1">{{job.job_Status}}</div>
    <div class="col-sm-8">{{job.jobDefinition_SearchName}}</div>
  </div>
  <div class="child row">
    <div *ngFor="let child of job.childJobs">
      <hjobnode [depth]="depth+20" [job]="child"></hjobnode>
    </div>
  </div>
</div>

css css

  style(): Object {
    return  { 'padding-left': this.depth + "px", 'width':'100%' };
  }

Your approach using padding was the right way to go.您使用填充的方法是正确的方法。 The easiest would be to nest those items within one another, so you don't need to think about the depth.最简单的方法是将这些项目相互嵌套,因此您无需考虑深度。

As Chris W. pointed out, this can be easily represented as a list, using ul (or ol ) and li s.正如 Chris W. 指出的那样,这可以很容易地表示为一个列表,使用ul (或ol )和li s。

 ul, li { margin: 0; padding: 0; list-style: none; } li>ul { padding-left: 20px; }
 <ul> <li>Item 1</li> <li>Item 2</li> <li> <ul> <li>Item 2.1</li> <li> <ul> <li>Item 2.1.1</li> </ul> </li> </ul> </li> <li> Item 3 <!-- you can even nest the ul directly inside an item !--> <ul> <li>Item 3.1</li> </ul> </li> </ul>

Hope that helped希望有所帮助

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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