我有来自MongoDb系列的锯齿状数据,如下所示:
$scope.data = [ { "fieldA": "value-a", "fieldB": "value-b" }, { "fieldA": "value-a", "fieldB": "value-b", "fieldC": "value-c" }]
使用...
angular.forEach(data, function(item){ $scope.colHeaders.push(item. ?????????) });
如何将字段名称作为列标题并避免重复?
答案 0 :(得分:0)
您可以使用Object.keys(未测试):
angular.forEach(data, function(item){
$scope.colHeaders.push(Object.keys(item));
});