如何在Typescript / Angular中使用Set / Array字段发布对象

时间:2019-03-18 10:54:14

标签: angular typescript

我上过这样的课:

export class LogModel {
..
componentSet: Set<string>;
constructor(componentSet: Set<string>) {
    this.componentSet = componentSet;
}

我需要将此类发布到Spring boot app。但是我有JSON反序列化的问题,因为: enter image description here

我必须使用

这样的转换方法
`private toArray(set) {
        let array: string[] = [];
        for (let i = 0; i < set.length; ++i)
            array[i] = set[i];
        return array;
    }`

为了拥有enter image description here 如何正确张贴此类?

1 个答案:

答案 0 :(得分:1)

在发送到post方法之前先做这样的事情

const postValue = Array.from(this.componentSet);

(OR)

const setValues = this.componentSet.values();
const postValue = Array.from(setValues);

然后发布postValue