我可以在数组中放入一些属性吗?
installments: string[];
我已经尝试过
installments: string[
name: string;
number: number
];
这是我的界面
export interface FiscalDocumentData {
id: string;
name: string;
number: number;
type: string;
company: string;
provider: string;
value: string;
paymentCondition: string;
checker: string;
approver: string;
product: string;
issueDate: string;
status: string;
activity: string;
comments: string;
installments: string[];
}
这是一个模拟的例子
this.data = [{
id: "de89cbb7-be6c-49e7-b3d5-6eef106cca7b",
name: "Linet Fawdrie",
number: 83,
type: "Audi",
company: "Gigazoom",
provider: "Crooks LLC",
value: "$1.56",
paymentCondition: "Peso",
checker: "Eziechiele Beecraft",
approver: "Randy Libri",
product: "NITROGLYCERIN",
issueDate: "10/10/2018",
status: "approved",
activity: "Support",
comments: "Lorem ipsum dolor sit amet",
installments: ['1', '12-14-2019', '5000', 'Payed']
}
答案 0 :(得分:0)
我看到分期付款中的所有值都是字符串,因此您需要字符串数组
installments: string[];
您的模型应该看起来像
declare module namespace {
export interface RootObject {
id: string;
name: string;
number: number;
type: string;
company: string;
provider: string;
value: string;
paymentCondition: string;
checker: string;
approver: string;
product: string;
issueDate: string;
status: string;
activity: string;
comments: string;
installments: string[];
}
}
您可以使用 JSON2TS 进行检查
答案 1 :(得分:0)
您不能向数组添加属性。只有对象。但是,如果您要用某种对象类型数组,请尝试以下操作:
installments: FiscalDocumentData[];