如何在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);