【问题标题】:Using multiple ng-repeat使用多个 ng-repeat
【发布时间】:2016-09-29 06:18:04
【问题描述】:
    <table class="table table-striped">
  <thead>
    <tr>
      <th>#</th>
      <th ng-repeat="header in headers">{{header}}</th>
    </tr>
  </thead>
  <tbody>
    <tr ng-repeat="table in tables">
      <td>{{$index+1}}</td>
      <td ng-repeat="header in headers">{{$parent.table.header}}</td>
    </tr>
  </tbody>
</table>

我有一个从服务器检索到的 json 数组。第一个 ng-repeat: 'headers' 包含我提取的那个 json 数组中的键。它在所有情况下都可以正常工作。 第二个 ng-repeat: 'tables' 包含接收到的 json 数组。我想要做的是对于 json 数组的每个元素,通过提供键值来查找数据。 这是我的多个 ng-repeat 代码。这不起作用,表格中没有打印任何数据,但如果我将{{$parent.table.header}} 更改为{{$parent.table}}{{header}},我可以在表格中看到数据。 问题是{{$parent.table.header}}我怎样才能正确地做到这一点?

【问题讨论】:

  • 不清楚您要在这里输出什么。您能否提供更多信息,特别是您的数据是什么样的,以及您希望在输出中看到什么?
  • 在 plunkr 中发布您的代码将用于解决您的问题

标签: html angularjs angularjs-ng-repeat ng-repeat


【解决方案1】:

尝试使用$parent.table[header] - 因为header 已经是一个字符串。

【讨论】:

  • 那行得通...但是 table 不是数组,它是一个 json 字符串。所以我可以像这样访问json?我以为我只能通过“点”访问它
  • 键是属性——但是当循环对象的键时,它们定义为字符串——然后你可以使用 ["STRING GOES HERE"]; stackoverflow.com/questions/3608246/…
猜你喜欢
  • 2016-05-25
  • 1970-01-01
  • 2022-11-11
  • 2015-10-07
  • 2017-07-24
  • 1970-01-01
  • 2014-07-11
  • 2015-03-21
  • 1970-01-01
相关资源
最近更新 更多