<input *ngIf="showAutoComplete"
[(ngModel)]="selected"
[typeahead]="uniqueCreatedBys"
[typeaheadOptionField]="'name'"
class="form-control"
(ngModelChange)=
"ObjectType('',userId = selected.id )">
我正在使用 ngx bootstarp 的 typehead,需要在前端部分访问名称,但在 ObjectType 函数中发送 id,我的 uniqueCreatedBys 包含名称和 id 的列表
//这是我的功能
ObjectType(q?: string, userId? : number, offset?: number, limit?: number) {
// console.log(this.objectTypes)
// const userId = this.selected ? this.objectTypes.find(obj => obj.createdBy === this.selected)?.createdById : undefined;
this.objectTypeService.fetchObjectTypes(q, userId , offset, limit).subscribe((response: any) => {
this.objectTypeService.resetObjectTypes();
this.objectTypeService.setObjectTypes(response);
this.objectTypes = this.objectTypeService.getObjectTypes();
this.totalCount = this.objectTypeService.getTotalDocsCount();
this.uniqueCreatedBys = this.getUniqueCreatedBys(this.objectTypes);
console.log(this.uniqueCreatedBys)
});
}