我有一个对象数组,我想使用ng-repeat构建一个表,该表将在正确的列中插入数据。

现在,我正在这样做,而我无法以正确的方式获取它。

请参阅Plunker for more details

<div class container>
  <div class="row">
    <div class="col-md-12">
      <table border='0' cellpadding='0' cellspacing='0'>
        <tr>
          <th>Time ()</th>
          <th>Room - One</th>
          <th>Room - Two</th>
          <th>Room - Three</th>
          <th>Room - Four</th>
        </tr>
        <tr ng-repeat="company in dataOne track by $index">
          <td>{{company.start}} - {{company.end}}</td>
          <td>{{company.company}}</td>
          <td>{{company.company}}</td>
          <td>{{company.company}}</td>
          <td>{{company.company}}</td>
        </tr>
      </table>
    </div>
  </div>
</div>

样本数据
        $scope.dataOne = [{

    "start": "7:30",
    "end": "8:00",
    "company": "Sony"
  }, {
    "start": "7:30",
    "end": "8:00",
    "company": "LG"
  }, {
    "start": "7:30",
    "end": "8:00",
    "company": "UPS"
  }, {
    "start": "7:30",
    "end": "8:00",
    "company": "MSI"
  }, {
    "start": "8:00",
    "end": "8:30",
    "company": "Samsung"
  }, {
    "start": "8:00",
    "end": "8:30",
    "company": "Tesco"
  }, {
    "start": "8:00",
    "end": "8:30",
    "company": "VW"
  }, {
    "start": "8:00",
    "end": "8:30",
    "company": "Audi"
  }, {
    "start": "9:00",
    "end": "9:30",
    "company": "BMW"
  }, {
    "start": "9:00",
    "end": "9:30",
    "company": "Sunoco"
  }, {
    "start": "9:00",
    "end": "9:30",
    "company": "Blizzard"
  }, {
    "start": "9:00",
    "end": "9:30",
    "company": "CS"
  }, {
    "start": "9:30",
    "end": "10:00",
    "company": "Mazda"
  }, {
    "start": "9:30",
    "end": "10:00",
    "company": "Nissan"
  }, {
    "start": "9:30",
    "end": "10:00",
    "company": "Porsche"
  }, {
    "start": "9:30",
    "end": "10:00",
    "company": "Hyundai"
  }]
  console.log($scope.dataOne)

最佳答案

如果我理解正确,您只想显示公司属于某个房间,这样就需要将房间中的公司分组

{
      "start": "8:25",
      "end": "9:00",
      "rooms":{
        3:{
          "company": "companyOne, Inc."
        }
      }
 }

您可以看到一个有效的示例here

关于javascript - 使用ng-repeat的AngularJS垂直表,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/40136888/

10-10 18:58