通过 WebService 我向前端发送一个 Json 并将其映射以将其所有内容放入一个表中,我想建立一个搜索方法来仅查看具有搜索到的字母的行。
组件.ts
allCountries:allCountries[];
applyFilter(event: Event) {
const filterValue = (event.target as HTMLInputElement).value;
this.allCountries.filter = filterValue.trim().toLowerCase();
} ^^^^^^^^^^^^
ERROR
映射
export class allCountries{
name:string;
iso2:string;
iso3:string;
unicode:string;
dial:string;
currency:string;
capital:string;
continent:string;
}
HTML
<mat-label for="ricerca">Ricerca</mat-label>
<input matInput type="text" name="searchString" (keyup)="applyFilter($event)" placeholder="Type to search..." />
<table mat-table [dataSource]="allCountries">
<ng-container matColumnDef="name">
<th mat-header-cell *matHeaderCellDef>Nazione</th>
<td mat-cell *matCellDef="let allCountries">{{allCountries.name}}</td>
</ng-container>
<ng-container matColumnDef="iso2">
<th mat-header-cell *matHeaderCellDef>iso 2</th>
<td mat-cell *matCellDef="let allCountries">{{allCountries.iso2}}</td>
</ng-container>
错误
error TS2322: Type 'string' is not assignable to type '{ <S extends allCountries>(callbackfn: (value: allCountries, index: number, array: allCountries[]) => value is S, thisArg?: any): S[]; (callbackfn: (value: allCountries, index: number, array: allCountries[]) => unknown, thisArg?: any): allCountries[]; }'.
我知道错误是因为“过滤器”可用于简单数组而不是对象数组。我没有发布所有代码,因为它与我的问题无关,因此毫无用处。谢谢您的帮助