【发布时间】:2016-07-26 12:19:36
【问题描述】:
如何顺序使用两个管道?
<div class="thread" *ngFor="thread of threadlist | bookmarkPipe | threadPipe"></div>
具体来说,我的线程有一个书签:布尔属性以及标签属性(单元、任务、子任务)。 所以我想要实现的是第一个管道过滤所有标记的线程,然后应用第二个管道(下)
export class ThreadPipe implements PipeTransform{
transform(array:Thread[], [unit,task,subtask]):any{
//See all Threads
if(unit == 0 && task == 0 && subtask == 0){
return array
}
//See selected Units only
if(unit != 0 && task == 0 && subtask == 0){
return array.filter(thread => {
return thread.unit === unit;
});
}
//See selected Units and Tasks
if (unit != 0 && task != 0 && subtask == 0){
return array.filter(thread => {
return thread.unit === unit && thread.task === task;
});
}
// See selected units, tasks, subtask
if (unit != 0 && task != 0 && subtask != 0){
return array.filter(thread => {
return thread.unit === unit && thread.task === task && thread.subtask === subtask;
});
}
}
}
【问题讨论】: