可以设置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;
}
这行得通。
由于您需要更改数组中的每个项目items
因此不需要使用 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 ;
}
return this.posts.concat(this.postss);
来自concat
的文档:
concat()
方法返回一个新数组,该数组由调用该数组的数组与作为参数提供的数组和/或值联接而成。