**这是添加/编辑记录的对话框,页面加载时绑定了库存目录名称。 itemCategory取决于invDept。并且项目组取决于itemcategory
单击编辑后填充特定项目记录的代码:绑定第一个下拉菜单InvDeptName,然后绑定类别下拉列表。 **
ngOnInit() {
if(this.dialogData!=null){
this.InventoryDepartments=this.dialogData.inventoryDepartmentList;
this.ItemForm=new FormGroup({
itemId:new FormControl(null),
itemName: new FormControl('',[Validators.pattern('^([a-zA-z\s]
{4,32})$'),Validators.required]),
inventoryDeptName:new FormControl('',Validators.required),
itemCategoryName:new FormControl('',Validators.required),
itemGroupName:new FormControl('',Validators.required),
strMaintenanceSchedule:new FormControl(null),
strCalibrationSchedule:new FormControl(null),
description:new FormControl(''),
isActive:new FormControl(true),
remarks:new FormControl('')
});
if(this.dialogData.itemId>0){
this.setFormData(this.dialogData);
}
}
}
setFormData(itemData:any){
this.ItemForm.controls.itemId.setValue(itemData.itemId);
this.ItemForm.controls.itemName.setValue(itemData.itemName);
this.ItemForm.controls.inventoryDeptName.setValue(itemData.inventoryDeptId);
this.BindItemCategory();
this.ItemForm.controls.itemCategoryName.setValue(itemData.itemCategoryId);
this.ItemForm.controls.itemGroupName.setValue(itemData.itemGroupId);
this.ItemForm.controls.strMaintenanceSchedule.setValue(itemData.strMaintainanceSchedule);
this.maintenanceSchedule=itemData.strMaintainanceSchedule > 0 ? true : false;
this.ItemForm.controls.strCalibrationSchedule.setValue(itemData.CalibrationSchedule);
this.calibrationSchedule=itemData.CalibrationSchedule > 0 ? true : false;
this.ItemForm.controls.description.setValue(itemData.description);
this.ItemForm.controls.isActive.setValue(itemData.isActive);
this.ItemForm.controls.remarks.setValue(itemData.remarks);
}
2:接下来的两个下拉列表未正确绑定,并且该值也未设置
维护计划文本框在运行时添加到itemgroup的特定值上。该文本框也不会在运行时以编辑模式添加。错误如下所示
仅看到上面指定的代码的表单,我可以建议:
[尝试设置整个formGroup的值,而不是分别设置每个控件,设置后,您可以记录表单值以检查是否正确,如果是,则在其他地方存在一些问题。
祝你好运