选择类型脚本中的JSON与数组绑定

时间:2019-07-20 04:03:53

标签: arrays json angular typescript

JSON

K

管道:

{
    "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"}
    ]
}

查找类(由nswag自动生成):

  transform(aList: Lookup[], lookUpName: string): Lookup[] {
    if (!aList || !lookUpName || aList.length === 0) {
        return aList;
    }

  return Array.of(aList[lookUpName])
}

HTML:

export interface ILookup {
    name?: string | undefined;
    value?: string | undefined;
    description?: string | undefined;
}

选择不绑定必需的值。我在做什么错了?

1 个答案:

答案 0 :(得分:1)

Array.of(aList[lookUpName])更改为aList[lookUpName]。一切都会正常。

 transform(aList: Lookup[], lookUpName: string): Lookup[] {

    if (!aList || !lookUpName || aList.length === 0) {
        return aList;
    }
    return aList[lookUpName];
}

StackBlitz