简体   繁体   English

单击表AngularJS中的过滤器

[英]Click filter in table AngularJS

I want to filter my data in table after click the button. 单击按钮后,我想过滤表中的数据。 Here is my filter : 这是我的过滤器:

app.filter('eyeFilterFunction',function(){
    return function(data, from) {
        if (!from) return data;
        var items = [];
        angular.forEach(data, function(item){
            if(item.weight != from) {
                items.push(item);
            }
        });
        return items;
    };
});

And my plunker : http://plnkr.co/edit/s7tuhKXFSt0Yv5BfI4h0?p=preview 和我的朋克: http ://plnkr.co/edit/s7tuhKXFSt0Yv5BfI4h0?p=preview

What i want - after click the button, only shows in table data with weight , where it is null in wehgit let it not show. 我想要的是-单击按钮后,仅在表数据中显示weight ,在wehgitnull ,使其不显示。 Thanks for answers in advance! 预先感谢您的答复!

try this 尝试这个

app.filter('eyeFilterFunction',function(){
    return function(data, from) {
        if (typeof from === 'undefined') return data;
        var items = [];
        for(var x of data){
          if(x.weight != from){
            items.push(x);
          }
        }
        return items;
    };
});

try this, 尝试这个,

http://plnkr.co/edit/jNid2ZwiDNLrwGx2rnKh?p=preview9rnKsXvEtJrxhOYDMa7o?p=preview http://plnkr.co/edit/jNid2ZwiDNLrwGx2rnKh?p=preview9rnKsXvEtJrxhOYDMa7o?p=preview

app.filter('eyeFilterFunction', function() {
  return function(data, from) {
    if(!from) return data;
    return data.filter(i => i.weight != null);
  };
});

in template, 在模板中

<tr ng-repeat="n in messages | eyeFilterFunction:filterText">

the button, 按钮,

<button class="btn btn-clear btn-sm" ng-click="filterText = !filterText">Filter!</button>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM