angularJs-----$filter过滤器使用 自定义过滤器

来源:互联网 发布:mac视频投放led 编辑:程序博客网 时间:2024/05/21 07:46

angularJs—–$filter过滤器使用 自定义过滤器

  • HTML
<table class="table table-striped table-border  ">                <tbody>                <tr>                    <th style="width: 60px;text-align: center;">编号</th>                    <th>农药名称</th>                    <th>包装规格</th>                    <th>销售价</th>                    <th>分类名称</th>                    <th>生产企业</th>                    <th>状态</th>                    <th>操作</th>                </tr>                <tr ng-repeat="item in pesticideList | filtrate">                    <td ng-bind="$index+1">1</td>                    <td ng-bind="item.pesticideRegName">农药名称</td>                    <td><span ng-bind="item.packQuantity">100</span> <span> <span ng-bind="item.packStandard"></span>/   <span ng-bind="item.packUnit"></span></span></td>                    <td><span ng-bind="item.sellPrice">0.00</span><span>元/ <span ng-bind="item.packUnit"></span></span></td>                    <td ng-bind="item.classify">肥料</td>                    <td ng-bind="item.produceCompany">浙江宜葆农科技术有限公司</td>                    <td class="th-green" ng-bind="item.status == 0 ? '正常' : '停用'" ng-class="item.status == 0 ? 'th-green' : 'th-red'">正常</td>                    <td style="cursor: pointer;"><span class="th-blue">编辑 </span><span class="th-blue"> | </span><span class="th-blue"> 删除 </span><span class="th-blue"> | </span><span class="th-blue"> 停用 </span></td>                </tr>                </tbody>            </table>

controller js

app.filter('filtrate', function() {     return function (arr) {        var array = [];        if( arr instanceof Array){            for(var i=0; i<arr.length ;i++){                if(arr[i].status == 0){                    array.push(arr[i]);                }            }        }        return array;    }})