GroupBy for Observable<todo[]>

丶灬走出姿态 提交于 2019-12-11 14:04:30

问题


I'm retrieving a flat list of todo items from firestore in my angular app (ionic framework). The returned list is an Observable list and I'm using the async pipe to show the list in my template. This list of todo items has a due date, and I would like to do some custom grouping on it for displaying with group headers in my todolist app.

the groups are:

overdue (duedate < today)
today (duedate == today)
later (duedate > today)

I'm experimenting with doing it in the view with some magic ngFor and ngIf, but it feels wrong. I'm also reading about GroupBy with RxJS, but open for other suggestions or help. Custom pipe?


回答1:


Just use different observables for that, there's no reason to make it overly complicated.

const items$ = /* … */;

const overdueItems$ = items$.filter(item => …);
const todayItems$ = items$.filter(item => …);
const laterItems$ = items$.filter(item => …);

Custom pipe?

Angular discourages the user of filtering pipes for performance reasons.



来源:https://stackoverflow.com/questions/48865032/groupby-for-observabletodo

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!