比较值后,在html视图上显示返回的信息

时间:2017-11-27 04:41:26

标签: javascript angularjs

我正在提供包含API信息的列表。然后,我与for日期进行比较。这是我的代码:

function taffy(){
        var  d = new Date();
        $scope.day = d.getDate();
        $scope.month = d.getMonth() + 1;
        $scope.year = d.getFullYear();
        $scope.today = $scope.year + "-" + $scope.month + "-" + $scope.day + "T00:00:00";
    }

function getBackAll (){
           $http.get('/api/Invoice?')
            .then(function(data){
                $scope.amadeus = data.data.Response;

                for(var i = 0; i< $scope.amadeus.length; i++){
                    if($scope.amadeus[i].ProgramPayDate === $scope.today && $scope.amadeus[i].StatusId === 3){
                        $scope.viroba = $scope.amadeus[i];
                        console.log($scope.viroba);
                    }
                }
                //console.log($scope.amadeus);
        });
    }

我正在做的是获得“今天”的价值,并且它有效。当我尝试在我的html视图上显示时出现问题:

<table align="center">
                        <thead>
                        <tr>
                            <th>{{today}}</th>

                        </tr>
                        </thead>
                        <tbody>
                        <tr>
                            <th>Company: {{viroba.Name}} Total: ${{viroba.Total}}</th>
                        </tr>
                        </tbody>
                    </table>

如果我有一个值,那就没关系,我展示它,但是,如果我有一个以上,只显示一个。我需要通过ng-repeat?

请帮帮我吗?

提前完成。

1 个答案:

答案 0 :(得分:0)

您似乎需要进行以下更改:

function getBackAll (){
           $http.get('/api/Invoice?')
            .then(function(data){
                $scope.amadeus = data.data.Response;

                for(var i = 0; i< $scope.amadeus.length; i++){
                    if($scope.amadeus[i].ProgramPayDate === $scope.today && $scope.amadeus[i].StatusId === 3){
                        $scope.viroba = $scope.amadeus[i];//Here $scope.viroba is object. You can convert it to array.
                        console.log($scope.viroba);
                    }else {
                     $scope.viroba = $scope.amadeus;
                    }
                }
                //console.log($scope.amadeus);
        });

HTML:

<table align="center">
                        <thead>
                        <tr>
                            <th>{{today}}</th>

                        </tr>
                        </thead>
                        <tbody>
                        <tr>
                            <th ng-repeat="viroba in viroba">Company: {{viroba.Name}} Total: ${{viroba.Total}}</th>
                        </tr>
                        </tbody>
                    </table>