Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
715 views
in Technique[技术] by (71.8m points)

angluar 中 我用ng-repeat 循环出一个表格,然后我想根据每一行内容的判断来增加不同的样式,求助?

问题已经解决,谢谢大家,么么哒

angluar 中 我用ng-repeat 循环出一个表格,然后我想根据每一行内容的判断来增加不同的样式

    <tr ng-repeat="user in vm.userList" ng-class="{'yellow':late,'red':noWork,'yellowRed':tooLate}">
        <td>{{(vm.currentPage-1)*vm.pageSize+$index+1}}</td>
        <td>{{user.username}}</td>
        <td>{{user.name}}</td>
        <td>{{user['kq-time']}}</td>

    </tr>
    

controller里的循环,根据内容去判断添加那个样式

angular.forEach($scope.vm.cache.list,function(val,key){
            if(date-initDate>0){
        
                $scope.late=false;
                $scope.noWork=false;
                $scope.tooLate=true;
            }else{
        
                $scope.late=false;
                $scope.noWork=true;
                $scope.tooLate=false;
            }
         })

结果不对,都添加了red这个样式

clipboard.png


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

你的判断标志只有 $scope.late,$scope.noWork, $scope.tooLate 这三个,每次循环都是在对这三个变量进行赋值,那最后出现的效果肯定是最后一次判断的结果了

像你上面的效果,必然是最后一次进了else的逻辑,nowork是true,样式为红色

简单的实现方式是把判断标志放在每个repeat的对象内部


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...