angular - 如何使用 p-listbox 过滤多个标签?
问题描述
我想过滤多个标签,有没有一种方法可以让 optionLabel 有多个选项?
<p-listbox [options]="sites" `enter code here`[(ngModel)]="selectedSite" class="ui-fluid" [listStyle]="{'max-height':'300px'}" filter="filter" optionLabel="name">
<p-header>
<strong>{{ 'select-site.choose' | translate}}</strong>
</p-header>
<ng-template let-site pTemplate="item">
<span>{{site.value.code}} - {{site.value.name}}</span>
</ng-template>
</p-listbox>
我想过滤代码和名称
解决方案
与其将选项设置为任意对象数组,不如将其设置为选择项数组,其标签包含要过滤的两个值。
siteOptions: SelectItem[] = sites.map(s => { value: s, label: s.name + s.code });
更新您的列表框元素:
<p-listbox [options]="siteOptions" [(ngModel)]="selectedSite" class="ui-fluid" [listStyle]="{'max-height':'300px'}" filter="filter">
您已经在使用项目模板来控制列表中每个元素的显示方式,因此可能不需要进行其他更改。
推荐阅读
- html - 将 3 个 div 浮动在另一个的顶部
- php - 根据具有多个连接的最新日期选择行-Code Ignitor
- java - 使用apache POI在excel表中添加新行时自动复制单元格公式
- java - 如何在lucene中搜索保留字符?
- python-3.x - 模拟模块方法
- r - 在 rmarkdown 的文本中打印 `ggplot2` 形状
- python - 读取多个数据文件时出现内存错误问题
- python-requests - Python 中的 XML 标记
- qt - SPI raspberry pi (master) & arduino due (slave)
- symfony - 如何在包含的模板之间共享变量(或者是否有替代方法)?