类型"数字"不能分配给类名类型 []



我收到错误

类型"数字"不能分配给设备输入类型 []

这是我的代码

id:number
reprobj:Reprocess;
this.reprobj.DeviceIds=this.id;

模型类代码

export class DeviceInput
{
ID:number
}
export class Reprocess
{
Flag:boolean
ProductID:number
DeviceIds: DeviceInput[]
}

如何解决此问题?

这是一个数组:

DeviceIds: DeviceInput[]

这是一个数字:

id:number

不能为数组分配数字。因此,请进行一些更改:

export class DeviceInput
{
ID: number;
constructor(_id:number) {
this.ID = _id;
}
}
export class Reprocess
{
Flag: boolean;
ProductID: number;
DeviceIds: DeviceInput[] = [];
}

您的代码:

this.reprobj.DeviceIds.push(new DeviceInput(someId));

相关内容

最新更新