我只想显示活动数据= 0。我得到了JSON中的所有数据,如下所示:
{
"StatusCode": 0,
"StatusMessage": "OK",
"StatusDescription": [
{ "h_id": "1",
"active": 0,
"date_created": "2018-08-02T15:28:52.000Z",
"serial_number": "4324fdfd",
"client_id": null
},
{ "h_id": "2",
"active": 0,
"date_created": "2018-08-02T15:28:52.000Z",
"serial_number": "3435fdf",
"client_id": null
},
{ "h_id": "3",
"active": 0,
"date_created": "2018-08-02T15:28:52.000Z",
"serial_number": "fgdge43",
"client_id": null
},
{ "h_id": "4",
"active": 1,
"date_created": "2018-08-02T15:28:52.000Z",
"serial_number": "edf43",
"client_id": 1
},
{
"h_id": "5",
"active": 1,
"date_created": "2018-08-02T15:28:52.000Z",
"serial_number": "3456677777",
"client_id": 2
},
....
{
"h_id": "10",
"active": 1,
"date_created": "2018-08-02T15:28:52.000Z",
"serial_number": "JDLk32",
"client_id": 200
}
]
}
在html中,我编写了以下代码以显示下拉列表中的所有数据:
<div class="input-field col s12">
<select formControlName="h_id" id="h_id" materialize="material_select" [materializeSelectOptions]="hbp" >
<option value="" disabled selected>Select Hb</option>
<option *ngFor="let hb of hbp" [value]="hb.h_id">{{hb.serial_number}}</option>
</select>
</div>
所有值在下拉选择中均显示正确,但我只希望在下拉菜单中显示具有 active:0
请问,您能问我如何仅显示数据active = 0
吗?
答案 0 :(得分:0)
在组件中创建一个吸气剂。
get zeroHbp() {
return this.hbp && this.hbp.filter(hb => hb.active === 0) || [];
}
<option *ngFor="let hb of zeroHbp" [value]="hb.h_id">{{hb.serial_number}}</option>
答案 1 :(得分:0)
请尝试* ngIf以检查ng-container中的状况
**<select>
<ng-container *ngFor="let hb of hbp">
<option *ngIf="hb.active == 0" [ngValue]="hb.h_id" ></option>
</ng-container>
</select>**
答案 2 :(得分:0)
您可以将html代码更改为以下内容:
<select id="h_id">
<option value="" disabled selected>Select Hb</option>
<ng-container *ngFor="let hb of hbp.StatusDescription">
<option *ngIf="hb.active === 0">{{hb.serial_number}}</option>
</ng-container>
</select>