ng-selectドロップダウンの2つのAPIフィールド「コードと名前」をマージしたいと思います。例えば:-
Code : MI
name : MI 3sPrime
Format : MI - MI 3sPrime
ドロップダウンに以下のコードを使用しました
Component.Html
<ng-select [items]="products" bindLabel="code" bindValue="id"
placeholder="Select Goods Receipt" clearAllText="Clear" formControlName="productId" [searchFn]="customSearchFn">
<ng-template ng-label-tmp let-item="item">
<span [ngOptionHighlight]="search">{{ item.code }} - {{ item.name }}</span>
</ng-template>
<ng-template ng-option-tmp let-item="item" let-search="searchTerm" let-index="index">
<span [ngOptionHighlight]="search">{{ item.code }} - {{ item.name }}</span>
</ng-template>
</ng-select>
Component.ts
customSearchFn(term: string, item: any) {
term = term.toLocaleLowerCase();
return item.code.toLocaleLowerCase().indexOf(term) > -1 ||
item.name.toLocaleLowerCase().indexOf(term) > -1;
}
検索:コードと名前が検索中にフェッチされています。しかし、私はコード、名前、そして与えられたフォーマットを検索したい(コード-名前)
以下は図です
ここで、「MI-」を検索していると、検索が機能しません
検索はフォーマットコードに適用する必要があります-名前..つまり、MIと入力すると、フィルタリングが機能する必要があります。方法はありますか?誰か助けてもらえますか?
これを試して
customSearchFn(term: string, item: any) {
term = term.toLocaleLowerCase();
return item.code.toLocaleLowerCase().indexOf(term) > -1 ||
item.name.toLocaleLowerCase().indexOf(term) > -1 ||
(item.code + " - " + item.name).toLocaleLowerCase().indexOf(term) > -1;
}
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加