【发布时间】:2019-11-28 23:52:04
【问题描述】:
JSON
{
"bloodGroup":[
{"Id":1, "Value":"O +ve", "Description":"OPositive"},
{"Id":2, "Value":"O -ve", "Description":"ONegative"},
{"Id":3, "Value":"AB +ve", "Description":"ABPositive"}
],
"Gender":[
{"Id":1, "Value":"Male", "Description":"Male"},
{"Id":2, "Value":"Female", "Description":"Female"}
]
}
管道:
transform(aList: Lookup[], lookUpName: string): Lookup[] {
if (!aList || !lookUpName || aList.length === 0) {
return aList;
}
return Array.of(aList[lookUpName])
}
查找类(从 nswag 自动生成):
export interface ILookup {
name?: string | undefined;
value?: string | undefined;
description?: string | undefined;
}
HTML:
<option *ngFor="let gender of aList | lookupFilter:'Gender'" [value]="gender.Id">
{{gender.Value}}
</option>
选择没有绑定所需的值。我做错了什么?
【问题讨论】:
-
我认为问题出在 Pipe 上。你能用完整的管道类更新问题吗
-
是否需要使用
lookupFilter。不能用作<option *ngFor="let gender of aList.Gender" [value]="gender.Id">{{gender.Value}}</option> -
似乎是一个不错的选择,没想到因为之前的场景不同,所以我使用的是 filterPipe。会试一试@SudarshanaDayananda
-
就这样工作了,谢谢@SudarshanaDayananda 我仍然很好奇为什么这不起作用。无论如何都会使用你提出的方法。
-
检查我的答案。
标签: arrays json angular typescript