加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

Angularjs过滤器中的变量名称

发布时间:2020-12-17 17:09:44 所属栏目:安全 来源:网络整理
导读:我正在使用搜索框(输入)来过滤表格结果.目前它有关StudentName列的过滤,但它必须是动态的. 让我们说: filter :{'RollNo' :test}filter :{'Dept' :test} 简而言之: input type="text" ng-model="test"table tr ng-repeat="x in names |filter :{'StudentNam
我正在使用搜索框(输入)来过滤表格结果.目前它有关StudentName列的过滤,但它必须是动态的.

让我们说:

filter :{'RollNo' :test}
filter :{'Dept' :test}

简而言之:

<input type="text" ng-model="test">

<table>
    <tr ng-repeat="x in names |filter :{'StudentName' :test}"></tr>
</table>

解决方法

按照以下方法 –
要搜索不同的内容,您需要使用不同的输入字段,否则您必须根据您的要求类型创建自定义过滤器

<label>Any: <input ng-model="search.$"></label> <br>
<label>Name only <input ng-model="search.name"></label><br>
<label>RollNo only <input ng-model="search.RollNo"></label><br>

<table>
  <tr ng-repeat="x in names | filter:search">
    <td>{{x.name}}</td>
    <td>{{x.RollNo}}</td>
  </tr>
</table>

编辑

这是您的自定义过滤器:

.filter('TableFilter',function(){
    return function(dataArray,type,filtervalue) {
        if (!dataArray) {
            return;
        }else{
            if(type === 'Name'){
                return dataArray.filter(function(item){
                    var term = item.name === filtervalue;
                    return term;
                });
            }else if(status === 'RollNo'){
                return dataArray.filter(function(item){
                    var term = item.RollNo === filtervalue;
                    return term;
                });
            }
        }
    }
});

<tr ng-repeat="x in names | TableFilter : dropDownvalue : test">

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读