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相关文章