“this.orders”是下面 API 的结果。我的问题是如何在 material_purchase_orders 下获取 material.name 并仅编辑其数量。你的解决方案是对的。我只是无法获得要编辑的这个 material.name 及其数量。
ts
this.route.paramMap
.switchMap((params: ParamMap) =>
this.purchaseOrderService.getOrder(+params.get('id')))
.subscribe(
(order:any) => {
this.orders = order;
console.log(order);
this.loading = false;
},
error => {
console.log(error);
this.loading = false;
})
};
this.myForm = this.fb.group({
rows: this.fb.array([])
})
initGroup() {
let rows = this.myForm.get('rows') as FormArray;
rows.push(this.fb.group({
prod_id: [null, Validators.required],
quantity: [null, Validators.required],
}))
}
JSON
{
"id": 11,
"reference": "pek567",
"supplier_id": 1,
"user_id": 1,
"project_id": 5,
"total": 100,
"transaction_date": "2017-10-08",
"created_at": "2017-10-31 13:10:44",
"updated_at": "2017-10-31 13:10:44",
"user": {
"id": 1,
"name": "John",
"email": "john@gmail.com",
"created_at": "2017-10-26 07:32:53",
"updated_at": "2017-10-26 11:58:44"
},
"supplier": {
"id": 1,
"name": "Not Available",
"address": "Not Available",
"city": "Not Available",
"contact_number": "Not Available",
"created_at": "2017-10-26 16:12:22",
"updated_at": "2017-10-26 16:12:22"
},
"material_purchase_orders": [
{
"id": 11,
"material_id": 49,
"purchase_order_id": 11,
"quantity": 1,
"unit": "pcs",
"price": 100,
"created_at": "2017-10-31 13:10:44",
"updated_at": "2017-10-31 13:10:44",
"material": {
"id": 49,
"sku": "D16789",
"name": "Door",
"created_at": "2017-10-26 03:33:06",
"updated_at": "2017-10-26 03:33:06"
}
}
],
"user_name": "John"
}