繁体   English   中英

类型 'number' 不能分配给类型 className []

[英]Type 'number' is not assignable to type className []

我收到错误

类型 'number' 不能分配给类型 DeviceInput []

这是我的代码

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));

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM