如果更新ng-repeat中使用的数组,如何更新ng-repeat div?

时间:2015-10-18 01:50:33

标签: javascript angularjs ng-repeat

我每次在JSP中的某个事件上点击filterClient函数时,我都会尝试更新数组displayCards。即使ng-repeat已更新,我的JSP中的displayCards也未获得更新。我错过了什么吗?

JS代码段

var ngApp = angular.module('ngApp', ['angularUtils.directives.dirPagination']);

ngApp.controller("listCardsCtrl", function ($scope, $filter, $compile) {

    $filterBy = $filter("filter");
    $orderBy = $filter('orderBy');

    $scope.renderAngularContent = function (element, data) {
        var template = angular.element(data);
        var result = $compile(template)($scope);
        element.html(result);
    }


    $scope.currentPage = 1, $scope.itemsPerPage = 1, $scope.maxSize = 5;
    $scope.savedFilter = [];
    $scope.filterFlag = false;
    $scope.trfList = [];
    $scope.filterCards = [];
    $scope.clientNames = [{"name": "CCE"}, {"name": "Barclays"}];
    $scope.statusList = [{"name": "Submitted"}, {"name": "Rejected"}];
    $scope.displayCards = [];
    $scope.showCards = [];
    $scope.trfList = jsonOutput;

    $scope.displayCards = $scope.trfList;

    $scope.filterClient = function (clientName) {
        $scope.key = "clientNames";
        $scope.value = clientName;
        $scope.savedFilter.push({'filterKey': $scope.key, 'filterKeyValue': $scope.value});
        $scope.applyFilter();
        //$scope.displayCards = $scope.filterCards;
    };

    $scope.filterCards = [];
    $scope.applyFilter = function () {
        $scope.filterCards = $scope.trfList;

        angular.forEach($scope.savedFilter, function (value, key) {
            if (value.filterKey == 'clientNames') {
                $scope.filterCards = $scope.trfList.filter(function (trf) {
                    var found = false;
                    if (value.filterKeyValue == trf.clientName) {
                        found = true;
                    }
                    return found;
                });
            }
        });

        //$scope.displayCards = [];
        //if($scope.filterCards.length!=0){

        $scope.displayCards = $scope.filterCards;
        /*}
         else{
         $scope.displayCards = $scope.trfList;
         }*/


    }

    //$scope.applyFilter();

    $scope.$watch('displayCards', function () {
        alert("coming");
        console.log($scope.displayCards);
        $scope.showCards = $scope.displayCards;
    })
});

0 个答案:

没有答案