简体   繁体   English

如何清除<p-autocomplete>选择值后?

[英]How to clear <p-autocomplete> after select value?

I have autocomplete and table.我有自动完成和表格。 After selecting an item, I need to add it to the array and remove it from the autocomplete.选择一个项目后,我需要将其添加到数组中并将其从自动完成中删除。

Сode below doesn't work下面的代码不起作用

<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;
}

employee is object员工是对象

you need to empty the employee property to make it empty after the change.您需要清空员工属性以在更改后将其清空。 I have assign an empty value to it assuming it is string.假设它是字符串,我已经为其分配了一个空值。

you can assign it to empty value depending upon its data type.您可以根据其数据类型将其分配给空值。

 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 = {}; }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM