当我的编辑表单加载时,我想用初始值填充表单数组。我的下拉选择选项被禁用,但它没有显示在垫选择中。
let selectedSpecs = this.editData.element.specifications;
this.spec = this.specForm.get('spec') as FormArray;
if (selectedSpecs.length != 0){
let selectedAttributeIds = [];
selectedSpecs.forEach((spec, i) => {
let attribute;
attribute = {'id': spec.itemDetailId, 'itemId':this.editData.element.itemId, 'name': spec.name};
this.spec.push(this.formBuilder.group({
attribute: attribute,
attributeSpec: spec.description
}));
selectedAttributeIds.push(spec.itemDetailId);
});
let attributes = [];
this.selectedCatAttributes.forEach((tempattribute) => {
let selected;
if (selectedAttributeIds.includes(tempattribute.id)) {
selected = true;
}else {
selected = false;
}
attributes.push(new Attribute(tempattribute, !selected));
});
this.attributeList.next(attributes);
}
<div formArrayName="spec" *ngFor="let spec of specForm.get('spec')['controls']; let i= index">
<div [formGroupName]="i">
<mat-card class="addShadow">
<button …Run Code Online (Sandbox Code Playgroud) javascript typescript formgroups angular6 angular-material-6
在我的程序中,我尝试更新用户的电子邮件。但这给了我一个例外说
嵌套异常是 com.fasterxml.jackson.databind.exc.MismatchedInputException:无法构造实例
java.util.HashSet
但是,当我通过添加技能和电子邮件更新用户时,它并没有给我这个例外。
我尝试创建一个默认构造函数,但它不起作用。我也尝试使用 Json Creator。它对我也不起作用。我可以看到问题是当我将技能集清空时,此异常正在上升。但我没有一个明确的想法,如何克服这个情况。
这是我的员工实体
@Entity
@Table(name = "Employee")
public class Employee implements Serializable{
private static final long serialVersionUID = -3009157732242241606L;
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private long emp_id;
@Column(name = "emp_fname")
private String emp_fname;
@Column(name = "emp_lname")
private String emp_lname;
@Column(name = "emp_email")
private String emp_email;
@Column(name = "emp_dob")
private Date emp_dob;
@ManyToMany(cascade = CascadeType.MERGE)
@JoinTable(name = "emp_skills",
joinColumns = @JoinColumn(name = "emp_id", referencedColumnName = "emp_id"),
inverseJoinColumns = @JoinColumn(name = "s_id",referencedColumnName = "s_id"))
private Set<Skills> skills; …Run Code Online (Sandbox Code Playgroud)