如何在 select 值之后清除 <p-autocomplete>?
How to clear <p-autocomplete> after select value?
我有自动完成和 table。选择一个项目后,我需要将它添加到数组并从自动完成中删除它。
下面的代码不起作用
<p-autoComplete
(completeMethod)="getEmployees($event.query)"
(onSelect)="change($event)"
[(ngModel)]="employee"
[suggestions]="employees"
field="title"
minLength="0"
></p-autoComplete>
change(newVal): void {
if (!newVal) {
return;
}
if (this.memberExists(newVal)) {
this.employee = null;
return;
}
this.document.employees.push(this.employee);
this.employee = null;
}
员工是对象
您需要清空员工属性,使其在更改后为空。假设它是字符串,我给它分配了一个空值。
您可以根据其数据类型将其分配给空值。
change(newVal): void {
if (!newVal) {
return;
}
if (this.memberExists(newVal)) {
this.commission = null;
return;
}
this.document.commission.push(this.commission);
this.commission = null;
// reset employee value to make it empty.
this.employee = {};
}
我有自动完成和 table。选择一个项目后,我需要将它添加到数组并从自动完成中删除它。
下面的代码不起作用
<p-autoComplete
(completeMethod)="getEmployees($event.query)"
(onSelect)="change($event)"
[(ngModel)]="employee"
[suggestions]="employees"
field="title"
minLength="0"
></p-autoComplete>
change(newVal): void {
if (!newVal) {
return;
}
if (this.memberExists(newVal)) {
this.employee = null;
return;
}
this.document.employees.push(this.employee);
this.employee = null;
}
员工是对象
您需要清空员工属性,使其在更改后为空。假设它是字符串,我给它分配了一个空值。
您可以根据其数据类型将其分配给空值。
change(newVal): void {
if (!newVal) {
return;
}
if (this.memberExists(newVal)) {
this.commission = null;
return;
}
this.document.commission.push(this.commission);
this.commission = null;
// reset employee value to make it empty.
this.employee = {};
}