AngularJS - 来自MongoDb锯齿状数据的动态表头

时间:2015-01-17 22:05:59

标签: angularjs

我有来自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. ?????????)
    });

如何将字段名称作为列标题并避免重复?

1 个答案:

答案 0 :(得分:0)

您可以使用Object.keys(未测试):

angular.forEach(data, function(item){
    $scope.colHeaders.push(Object.keys(item));
});