[英]How to reset filter in Angular 4
目前,我有多个过滤器。 我想重置过滤器,但是它不起作用。
showOnlyMyRequest(){
this.requests = this.requests.filter(request => request.requestedBy === 'John Doe');
}
showAllRequest(){
this.requests = this.requests.filter(request => request.requestedBy === '*');
}
在上面的示例中, showAllRequest()
不会重置先前的过滤器。
从MDN网络文档 :
The filter() method creates a new array with all elements that pass the test implemented by the provided function.
因此,您的请求数组成为返回的.filter(),如果需要显示是否过滤请求,则应将过滤后的值存储在其他位置。
如果您决定从搜索文本字段向搜索功能发送参数,则可以尝试此操作。 让我知道是否有更好的解决方案,以便我也能改善自己。 提前致谢。
showAllRequest(parameter1){
if (parameter1 === '') {
/* call getmethod or the whole array variable got during get mehtod
*/
}
this.requests = this.requests.filter(request => request.requestedBy
=== '*');
}
下面的编码版本:
filterform(search) {
if (search === '') {
this.getFormSettings();
}
this.requests = this.requests.filter(request =>
request.requestedBy.indexOf(search.toLowerCase()) >= 0 === '*');
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.