angularjs过滤json数组中的空值

时间:2017-01-12 14:15:32

标签: javascript angularjs arrays json ng-repeat

我的Json数组如下

[["2017-01-11",8327.8,8389.0,8322.25,8380.65,192285417.0,8938.68],["2017-01-10",8262.7,8293.8,8261.0,8288.6,147312927.0,6904.57],["2017-01-09",8259.35,8263.0,8227.75,8236.05,102211190.0,5197.62],["2017-01-06",8281.85,8306.85,8233.25,8243.8,143689850.0,7298.74],["2017-01-05",8226.65,8282.65,8223.7,8273.8,163957452.0,8180.68],["2017-01-04",8202.65,8218.5,8180.9,8190.5,136476345.0,6543.13],["2017-01-03",8196.05,8219.1,8148.6,8192.25,131186021.0,6053.67],["2017-01-02",8210.1,8212.0,8133.8,8179.5,null,null],["2016-12-30",8119.65,8197.0,8114.75,8185.8,131457250.0,5800.7],["2016-12-29",8030.6,8111.1,8020.8,8103.6,null,null]]

我正在使用以下角度js脚本来提取记录

            <table border="1" cellpadding="5" cellspacing="0">
            <thead>
            <tr>
              <th>Sno.</th>
              <th ng-repeat="header in headers">{{ header }}</th>
            </tr>
            </thead>
            <tbody>
                <tr ng-repeat="row in data">
                    <td>{{$index+1}}</td>
                    <td ng-repeat="(key,info) in row">{{info}}</td>
                </tr>
            </tbody>
      </table>

Angular JS Code

                $http.jsonp(url)
                    .success(function(data){
                    console.log(data);
                    $scope.headers=data.dataset.column_names;
                    $scope.description=data.dataset.description;
                    $scope.data=data.dataset.data;
                });

问题是代码在数组中的行中找到空值时会中断。例如整行["2017-01-02",8210.1,8212.0,8133.8,8179.5,null,null] 从表中遗漏,因为它最后有空值。

我得到的输出是 this

1 个答案:

答案 0 :(得分:0)

检查后端函数,如果要在json对象中插入的值不为null,则在条件为真时插入它。