我是 Angular 的新手,我一直在努力让不同的部分一起工作。我有一个来自 PrimeNG 的 p-orderList,它显示 JSON 对象列表和一个 p-dropDown,它从listedObjects 中读取一个属性并显示所有可能的选项。我需要过滤 orderList 以便在未选择任何内容时显示所有可能的选项,或者过滤它以仅显示所选的种类。
我填充了下拉菜单并在更改时触发。我还可以使用内置函数的打字稿进行过滤。我不知道该怎么做是将它附加到 orderList。任何帮助是极大的赞赏。
HTML
<p-dropdown [options]="getExistingTypes()" [(ngModel)]="selectedType" [style]="{'width':'83%'}" (onChange)="onCategoryChange(selectedType)"></p-dropdown>
<div style="display: flex; justify-content: center; flex-direction: row; text-align: center;">
</div>
<p-orderList [value]="devices" [metaKeySelection]="false" [listStyle]="{'height':'400px'}" header="Devices" controlsPosition="right" dragdrop="false" [(selection)]="selected" [responsive]="true">
<ng-template let-device pTemplate="item">
<div style="font-size: x-large">
{{device['object_name'] | noquotes}}
</div>
<div>
<label>mac: </label>{{device.deviceData.MAC}}
</div>
<div>
<label>id: </label>{{device['object_identifier']}}
</div>
<div>
<label>type: </label>{{device['object_type']}}
</div>
</ng-template>
</p-orderList>
TS
onCategoryChange(selectedType){
var results = this.devices.filter(element => {return element.object_type === selectedType});
console.log(results);
}