简体   繁体   English

离子性-单击某项应更新列表

[英]ionic - clicking an item should update the list

I have a list of items with ngIf like the following 我有ngIf的商品清单,如下所示

<ion-list>
  <ion-item *ngIf="isItemInThisYear(item.id)">  
</ion-list>

Each item can appear several times but only the records from this year will appear. 每个项目可以出现几次,但只会显示今年的记录。 This works. 这可行。

When clicking an item inside this list, I want to refresh the list but this time, the list should only show records of the selected item (regardless the date). 单击此列表中的项目时,我想刷新列表,但是这次,该列表应仅显示所选项目的记录(不考虑日期)。

I understand that I should change (name as well) isItemInThisYear to accommodate either options but how can I send the value/parameter from the clicked item to the whole page so it will reload its list with the relevant parameter? 我知道我应该更改(名称)isItemInThisYear来容纳这两个选项,但是如何将单击项的值/参数发送到整个页面,以便它将带有相关参数的列表重新加载?

Have you tried adding a click handler and passing the item in that way? 您是否尝试过添加点击处理程序并以这种方式传递项目? I'm guessing you'll also want to make this a button (or similar) if it's meant to be clicked. 我猜您也希望将其设为按钮(或类似按钮)(如果要单击)。

<button ion-item (click)="filterList(item)" *ngIf="shouldItemBeDisplayed(item.id)"></button>

Also, you may want to consider updating an observable or a member variable with the list of items to be displayed. 另外,您可能要考虑使用要显示的项目列表来更新可观察的变量或成员变量。 That may allow you to always bind buttons to all the known items you want to show, in place of executing an *ngIf on every item to determine if it should be displayed or not. 这样可以使您始终将按钮绑定到要显示的所有已知项目,而不是对每个项目执行*ngIf以确定是否应显示该按钮。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM