javascript - Angularjs 过滤器不适用于 ng-repeat

标签 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>

这些是我的 Controller 功能;

$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”的值没有改变...

请帮忙...

最佳答案

您应该做的是将模型添加到其过滤器选项中,我想特别是具有这些数字的 div。

现在我不太明白作为武器配置文件愿望 list ,但在他们的配置文件中,你必须给出ng-model,例如ng-model =“profileSelected”

并在您的列表中添加

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

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

关于javascript - Angularjs 过滤器不适用于 ng-repeat,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39886020/

相关文章:

html - ng-if 和 ng-show 在我的 Ionic 应用程序中都不起作用

javascript - Dygraph - 具有垂直缩放功能的实时数据更新

javascript - angularjs 在我的代码中不起作用

javascript - Angular : How to use <md-radio-button> inside <table> with ng-repeat

javascript - AngularJS md-tabs 的更改索引根本没有效果

cordova - 是否可以播放多个内嵌视频

javascript - 视差 "scrolling"仅通过导航

javascript - 提醒消息并重定向(或不重定向)

angularjs - 使用 angularjs 的嵌套选项卡

android - 设备上出现错误 'ionic run Android'