我正在尝试有条件地将引导程序 col-xs-4 的三个包装成一行。我的 col-xs-4 的渲染效果很好,但我不知道如何将它们有条件地包裹在一行中。这是我现在的 NgFor:
<div class="col-xs-4" *ngFor='let linkGroup of linkGroups | siteMapText: siteMapTextFilter; let i=index'>
<ul class="list-unstyled">
<li class="heading">
<div class="clearfix">
<span [className]="linkGroup.ContainerCssClass">
<span [className]="linkGroup.CssClass"></span>
</span>
<a href="#">
<strong class="heading-text">{{linkGroup.Title}}</strong>
</a>
</div>
</li>
<li *ngFor='let link of linkGroup.Links'>
<a href="#" class="link">
<span [className]="link.CssClass"></span>
<span class="item">{{link.Title}}</span>
</a>
</li>
</ul>
</div>
我想做的是这样的事情,但我知道它是错误的,那么正确的方法是什么:
<div *ngIf='i % 3== 0' class="row">
<div class="col-xs-4" *ngFor='let linkGroup of linkGroups | siteMapText: siteMapTextFilter; let i=index'>
<ul class="list-unstyled">
<li class="heading">
<div class="clearfix">
<span [className]="linkGroup.ContainerCssClass">
<span [className]="linkGroup.CssClass"></span>
</span>
<a href="#">
<strong class="heading-text">{{linkGroup.Title}}</strong>
</a>
</div>
</li>
<li *ngFor='let link of linkGroup.Links'>
<a href="#" class="link">
<span [className]="link.CssClass"></span>
<span class="item">{{link.Title}}</span>
</a>
</li>
</ul>
</div>
</div>
编辑
答案正如 Gunter 建议的那样,将数据重新组织成行。然后我可以将模板组织成这样:
<div class="row" *ngFor='let linkRow of linkRows| siteMapRowText: siteMapTextFilter'>
<div class="col-xs-4" *ngFor='let rowCol of linkRow.RowGroups'>
<ul class="list-unstyled">
<li class="heading">
<div class="clearfix">
<span [className]="rowCol.ContainerCssClass">
<span [className]="rowCol.CssClass"></span>
</span>
<a href="#">
<strong class="heading-text">{{rowCol.Title}}</strong>
</a>
</div>
</li>
<li *ngFor='let link of rowCol.Links'>
<a href="#" class="link">
<span [className]="link.CssClass"></span>
<span class="item">{{link.Title}}</span>
</a>
</li>
</ul>
</div>
</div>