javascript – 如果使用angular js的任何属性的所有json值为null,如何隐藏表列

前端之家收集整理的这篇文章主要介绍了javascript – 如果使用angular js的任何属性的所有json值为null,如何隐藏表列前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

Plunker sample

How to hide table column if all json value is null for any property
using angular js

index.js

var app = angular.module('plunker',[]);
app.controller('MainCtrl',function($scope) {
  $scope.name = 'World';
  $scope.isArray = angular.isArray;
  $scope.data = [{
    "Id": null,"Title": "US","Description": "English - United States","Values": [{
      "Id": 100,"LanId": 1,"KeyId": 59,"Value": "Save"
    }]
  },{
    "Id": null,"Title": "MX","Description": "test","Title": "SE","Description": "Swedish - Sweden","Value": "Save"
    }]
  }]
  $scope.cols = Object.keys($scope.data[0]);
  $scope.notSorted = function(obj) {
    if (!obj) {
      return [];
    }
    return Object.keys(obj);
  }
});

的index.html

最佳答案
您可以过滤掉只有空值的列:

JavaScript的

$scope.cols = Object.keys($scope.data[0]).filter(function(col) {
    return $scope.data.some(function(item) {
      return item[col] !== null;
    });
});

并检查模板是否应该呈现此列:

HTML

Plunker

http://plnkr.co/edit/PIbfvX6xvX5eUhYtRBWS?p=preview 原文链接:https://www.f2er.com/css/427222.html

猜你在找的CSS相关文章