我正在上课,我遇到了一些麻烦:
我得到的信息是:
TypeError:_this.Order.orderRow未定义
当我尝试将新行推送到orderRow数组时会生成异常。
这是代码:
export class Order {
public orderRow?: OrderRow[];
public rowNumber?: number;
constructor(values: Object = {}) {
Object.assign(this, values);
}
}
export class OrderRow {
public rowNumber:number;
public idSaleOrderRow?: number;
public idCollection?: number;
public idProduct?: number;
public txtCollection?: string;
public txtName?: string;
public productName?: string;
public vQty?: number;
public vQtyFill?: number;
public vSellPrice?: number;
public vCustomerPrice?: number;
public vCustomerPriceFinal?: number;
constructor(values: Object = {}) {
Object.assign(this, values);
}
}
Order: Order = <Order>{};
...............
...............
let r:OrderRow = {
rowNumber: newRowNumber,
idSaleOrderRow: null,
idCollection: res.result.idCollection,
idProduct: res.result.idProduct,
txtCollection: res.result.txtCollection,
txtName: res.result.txtName,
productName: res.result.productName,
vQty: 1,
vQtyFill: null,
vSellPrice: res.result.vSellPrice,
vCustomerPrice: res.result.vSellPrice,
vCustomerPriceFinal: res.result.vSellPrice
};
this.Order.orderRow.push(r);
我该如何解决?
感谢支持
答案 0 :(得分:2)
您难以将对象文字转换为构造Order
类的新实例,您需要使用Order
运算符调用new
构造函数:
Order: Order = new Order({});
还应初始化orderRow
字段:
export class Order {
public orderRow?: OrderRow[] = [];
}