可以设置PipeTransform多个过滤器吗?
我试试
posts;
postss;
transform(items: any[]): any[] {
if (items && items.length)
this.posts = items.filter(it => it.library = it.library.replace("WH","Warehouse"));
this.postss = items.filter(it => it.collection = it.collection.replace("CL","Central Library"));
return this.posts,this.postss;
}
这不起作用
但
posts;
transform(items: any[]): any[] {
if (items && items.length)
this.posts = items.filter(it => it.library = it.library.replace("WH","Warehouse"));
return this.posts;
}
这有效。
答案 0 :(得分:1)
由于您需要更改filter
数组中的每个项目,因此无需使用forEach
,请改用 transform(items: any[]): any[] {
if (items && items.length){
items.forEach((it,index,array) => {
array[index].library = it.library.replace("WH","Warehouse");
array[index].collection = it.collection.replace("CL","Central Library");
});
}
return items ;
}
并应用更改:
.clear {
clear: both;
}
答案 1 :(得分:0)
return this.posts.concat(this.postss);
来自concat
的文档:
concat()
方法返回一个新数组,该数组由调用它的数组组成,并与作为参数提供的数组和/或值连接。