AngularJs-通过检查标题名称填充表

问题描述 投票:0回答:1

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

我称为Populate table with ng-repeat and check matching header data

已完成:我可以将标题动态添加到表/列中。

工作代码在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
}

enter image description here

需要做:现在,我必须通过检查列名来用相应的值填充表。我正在AngularJS 1.6.9中工作

javascript angularjs html-table angularjs-ng-repeat javascript-objects
1个回答
0
投票

通过添加小的更改,现在我可以填充表格了,

我遵循的代码如下,

<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>

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

供参考

Populated Table

热门问题
推荐问题
最新问题