我有一个表单,它具有固定字段以及从数据库创建的动态字段。字段每次都可能不同。因此,如何访问此类类别对象的JSON格式的动态生成的formControl值。
输出为:-
Category:[
{
"label": "test1",
"measurements": {
length:10,
Shoulder:20,
Chest: 20
}
},
{
"label": "test2",
"measurements": {
stomach:10,
thigh:20 }
}
]
<div *ngFor="let item of clickCategoryData let pointIndex=index">
<p><b>{{item.label}}</b></p>
<div *ngFor="let measurement of item.measurements;">
<label>{{measurement.name}}</label>
<input type="number" class="box" [placeholder]="measurement.name" [id]="measurement.id" required>
</div>
</div>
答案 0 :(得分:3)
将现有数组转换为此所需的输出数组
this.clickCategoryData.forEach(
data => {
let jsonObj = {}
data.measurements.forEach(mes => jsonObj[mes.name] = "")
data.measurements = jsonObj
}
)