2017-01-12 108 views
0

的json数组如下angularjs过滤空值

[["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> 

角JS代码

   $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

+0

您正在使用哪个版本的Angular? – superUser

+0

为什么不在“.success”事件处理函数中检查null数据,然后再访问它的字段? – vvtx

回答

0

入住后端功能,如果你想在JSON对象插入值不为空,并插入它,如果条件为真。