AngularJs - 通过检查 header 个名称来填充表格

AngularJs - Populate the tables by checking header names

我有两个 objects,一个包含选定的记录,另一个包含选定的字段。现在我需要通过检查列 header 名称或值来动态填充 table。

我提到了

已完成: 我能够将 header 动态添加到 table/columns.

工作代码在Plunker

HTML

<table class="dataTable no-footer leadTable">
    <thead>
        <tr role="row">
            <th>
                <input type="checkbox" ng-model="selectedSObject[key]" class="select_tertiary_selectAll" />
            </th>
            <th ng-repeat="k in sFields[key]" ng-value="{{k.name}}" style="font-weight: 400; border-right: none; background-color: #0070d2; padding: 10px 18px;">
                <div> {{k.label}} </div>
            </th>
        </tr>
    </thead>
    <tbody>
        <tr role="row" ng-class="odd" ng-repeat="record in value.filtered">
            <td>
                <input type="checkbox" ng-model="record.checked" />
            </td>
            <td ng-repeat="(key_1, value_1) in record" style="padding: 10px 18px;">
                <div> {{value_1}} </div>
            </td>
        </tr>
    </tbody>
</table>

JS

$scope.sFields = getSFields($scope.sObjectCSVData);
$scope.iterableRecords = getiterableRecords($scope.sObjectCSVData, allRecords)

function getiterableRecords(sCSVData, allRecords) {
  var sObjectRecords = {};
  if (allRecords) {
      Object.entries(sCSVData).forEach(function(key) {
          if (sCSVData[key[0]].filtered.length != 0) {
              if (sObjectRecords[key[0]]) {
                  sObjectRecords[key[0]].push(sCSVData[key[0]].filtered)
              } else {
                  sObjectRecords[key[0]] = []
                  sObjectRecords[key[0]].push(sCSVData[key[0]].filtered)
              }
          }
      });
  }
  return sObjectRecords
}

function getSFields(sCSVData) {
  var fields = {};
  Object.entries(sCSVData).forEach(function(key) {
      if (sCSVData[key[0]].filtered.length != 0) {
          for (var i = 0; i < sCSVData[key[0]].sObjectFields.length; i++) {
              if (fields[key[0]]) {
                  fields[key[0]].push(sCSVData[key[0]].sObjectFields[i])
              } else {
                  fields[key[0]] = []
                  fields[key[0]].push(sCSVData[key[0]].sObjectFields[i])
              }
          }
      }
  });
  return fields
}

需要做的事情: 现在我必须通过检查列名来用相应的值填充 table。 我在 AngularJS 1.6.9

工作

通过添加小改动,现在我可以填充 table、

我遵循的代码如下,

<tbody>
 <tr role="row" ng-class="odd" ng-repeat="record in value[0]">
   <td>
    <input type="checkbox" ng-model="record.checked" />
   </td>
   <td ng-repeat="k in sFields[key]" style="padding: 10px 18px;">
     {{record [k.name]}} </div>
   </td>
 </tr>

工作代码在下面提到的 plunker 中, Populate the table by checking the header name

供参考