【问题标题】:angularjs filter null values in json arrayangularjs过滤json数组中的空值
【发布时间】:2017-01-12 14:15:32
【问题描述】:

我的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]]

我正在使用以下 Angular 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 代码

                $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

【问题讨论】:

  • 您使用的是哪个版本的 Angular?
  • 在访问 .success 事件处理程序的字段之前,为什么不检查 null 的数据?

标签: javascript angularjs arrays json ng-repeat


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-07-18
    • 2016-10-22
    • 1970-01-01
    • 2019-12-30
    • 2016-07-09
    • 2016-11-08
    • 2021-10-30
    相关资源
    最近更新 更多