Angularjs过滤器无法使用ng-repeat

时间:2016-10-06 01:16:05

标签: javascript angularjs ionic-framework angularjs-ng-repeat angularjs-filter

当我使用函数更改过滤器值时,Angularjs过滤器无法使用ng-repeat ...我是angularjs的新手。

这些是我的html按钮,必须使用'ng-click'功能更改过滤器值;

<span>
    <a class="button button-stable" ng-class="class('static')"
       ng-click="activate('static','','')">
        All
    </a>
</span>
<span ng-repeat="profiles in cardList | unique:'profile'">
    <a class="button button-stable" ng-class="class($index)"
       ng-click="activate($index,profiles,profiles.profile);">
        {{profiles.profile}}
    </a>
</span>

这些是我的控制器功能;

$scope.cardList = [
    {id: 1, serial_number: '35986580', card_number: 'BG9S8W7DJSKLA9', profile: '512', expiry_date: '5-1-2017'},
    {id: 2, serial_number: '35986581', card_number: 'ASLWODS6F5812H', profile: '512', expiry_date: '5-1-2017'},
    {id: 3, serial_number: '35986582', card_number: '9A5S218LSKJBMC', profile: '768', expiry_date: '5-1-2017'},
    {id: 4, serial_number: '35986583', card_number: 'XLCKDIGOSJS092', profile: '1024', expiry_date: '5-1-2017'},
    {id: 5, serial_number: '35986584', card_number: 'XKSODKO0CNJSUW', profile: '1024', expiry_date: '5-1-2017'},
    {id: 6, serial_number: '35986585', card_number: 'PLHG0G9M746172', profile: '2048', expiry_date: '5-1-2017'},
    {id: 7, serial_number: '35986586', card_number: '5DF888F9EGVNDJ', profile: '2048', expiry_date: '5-1-2017'},
    {id: 8, serial_number: '35986587', card_number: 'D6F5G49ILMA9SF', profile: '4096', expiry_date: '5-1-2017'}
];
$scope.class = function(index, item){
    if ($scope.selected == index){
        return 'button-dark active';
    } else {
        $scope.staticAll = '';
        return '';
    }
}
$scope.activate = function(index, item, profile){
    if (index != 'static'){
        $scope.selected = index;
        $scope.filterProfile = profile;
        $scope.staticAll = '';
    } else {
        $scope.selected = 'static';
        $scope.filterProfile = '';
        $scope.staticAll = 'button-dark active';
    }
}

这是过滤器无法正常工作的地方;

<tr ng-repeat="card in cardList | filter: filterProfile">
                <td class="center">{{card.profile}}</td>
                <td class="center">{{card.expiry_date}}</td>
                <td class="center"><a class="button button-medium button-energized">Assign</a></td>
            </tr>

这是一张图片;

screenshot

我想使用个人资料按钮过滤结果,但'filterProfile'的值不会改变......

请帮忙......

2 个答案:

答案 0 :(得分:0)

你应该做的是将模型带到其过滤器选项,我想象特别是带有这些数字的div。

现在我不太了解作为武器配置文件的愿望清单,但是,在他们的配置文件中,你必须提供诸如ng-model = "profileSelected"

之类的ng-model

在您的列表中添加

<ion-item ng-repeat="card in cardList | filter: profileSelected">

为了获得更好的帮助,您可以创建一个codepen吗?

答案 1 :(得分:-1)

我不太清楚你想要什么样的终端产品,但我可以告诉你,这不是定制过滤器的定义方式。格式类似于

    var app = angular.module('buttonApp',[]);
    app.filter('myFilter', function() {
    return function(x) {
        //filter goodness in here
      }    
    })

您可以在https://docs.angularjs.org/tutorial/step_11

找到过滤器的官方文档