Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/33.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在typescript/angular中使用Set/Array字段发布对象_Angular_Typescript - Fatal编程技术网

如何在typescript/angular中使用Set/Array字段发布对象

如何在typescript/angular中使用Set/Array字段发布对象,angular,typescript,Angular,Typescript,我的课程是: export class LogModel { .. componentSet: Set<string>; constructor(componentSet: Set<string>) { this.componentSet = componentSet; } 导出类日志模型{ .. 组件集:集合; 构造函数(componentSet:Set){ this.componentSet=componentSet; } 我需要将这个类发布到Spring

我的课程是:

export class LogModel {
..
componentSet: Set<string>;
constructor(componentSet: Set<string>) {
    this.componentSet = componentSet;
}
导出类日志模型{
..
组件集:集合;
构造函数(componentSet:Set){
this.componentSet=componentSet;
}
我需要将这个类发布到Spring boot应用程序中。但是我遇到了JSON反序列化的问题,因为:

我必须使用像这样的变换方法

`private toArray(set) {
        let array: string[] = [];
        for (let i = 0; i < set.length; ++i)
            array[i] = set[i];
        return array;
    }`
`private toArray(集合){
let数组:字符串[]=[];
for(设i=0;i
为了拥有
如何正确发布此类?

在发送到POST方法之前,请执行此操作

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


然后发布
postValue

以便将
Set
转换为
Array
?这正是您想要的吗?@ArpitMeena否。我将此方法用于:componentSet:[]如果您满意,请接受答案。从(this.componentSet)开始就足够了。
const setValues = this.componentSet.values();
const postValue = Array.from(setValues);