Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/425.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何在更新ng repeat中使用的数组时更新ng repeat div?_Javascript_Angularjs_Ng Repeat - Fatal编程技术网

Javascript 如何在更新ng repeat中使用的数组时更新ng repeat div?

Javascript 如何在更新ng repeat中使用的数组时更新ng repeat div?,javascript,angularjs,ng-repeat,Javascript,Angularjs,Ng Repeat,每次在JSP中的某个事件中点击filterClient函数时,我都会尝试更新数组显示卡ng repeat也没有得到更新。我错过什么了吗 JS片段: var ngApp = angular.module('ngApp', ['angularUtils.directives.dirPagination']); ngApp.controller("listCardsCtrl", function ($scope, $filter, $compile) { $filterBy = $filt

每次在JSP中的某个事件中点击
filterClient
函数时,我都会尝试更新数组显示卡<即使更新了
displayCards
,我的JSP中的code>ng repeat也没有得到更新。我错过什么了吗

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;
    })
});

请清理您的代码,只发布与您的问题相关的内容。另外,在使用ng-repeat的地方包括HTML。只需将新视图推到当前迭代数组中。如果我没有错,根据angular JS的双向数据绑定,只要它迭代的数组发生更改,ng-repeat就应该更新。这种理解正确吗?@Chandan说得对。每当它所迭代的数组被更新时,ngRepeat指令自动更新视图数组。