【发布时间】:2021-04-22 18:01:37
【问题描述】:
我想输出不同英寸尺寸的自行车。为此,我有一个带有数组的 json 文件。
[{
"name": "Mountainbike",
"img_url": "assets/img/mountainbike.jpg",
"mount_size": [{"mount_s": "26"},
{"mount_s": "26"}]}]
在我的组件中,我调用了 json 文件
bike.component.ts
export class BikeSelectComponent implements OnInit {
biketypes: Biketype[] = [];
constructor(private apiService: ApiService) {
this.apiService
.getBikes()
.subscribe((biketypes) => (this.biketypes = biketypes));
}
ngOnInit(): void {}
}
我想为每英寸尺寸生成一个额外的按钮。我该怎么做?
bike.component.html
<div class="container" >
<div class="row">
<div class="col-12 "><h1>Welcome</h1></div>
</div>
<div class="row text-center">
<div class="col" *ngFor="let biketype of biketypes">
<figure>
<img src="{{biketype.img_url}}" alt="" width="200px" height="200px">
<figcaption class="bike-name">{{biketype.name}}</figcaption>
<figcaption ><button class="btn-size">{{biketype.mount_size}} Zoll</button></figcaption>
</figure>
</div>
</div>
</div>
【问题讨论】:
-
2 个按钮用于 2 个 mount_s?
-
每英寸大小的“mount_size”一个按钮。因此,一个 26 英寸的按钮和一个 28 英寸的按钮,例如
-
在您的 json 中看不到 28 英寸。
-
我相信 harleybl 的以下回答是正确的。
-
Aakash 对不起,我不小心在 2 次中写了 26。它应该是一次 26 和一次 28