当我有json之类的代码时,我经常做一个嵌套的ng-repeat循环遍历子数据

[
 { "accountnum": 1,
   "name": "foo",
   "subacct": [
      { "accountnum": 1-1,
        "name": "bar"
      } ...
    ]
  } ...
]


然后我使用这种模式:

     <tr ng-repeat-start="a in cac.costAccounts">
          <td>{{a.first_name}} {{a.last_name}}</td>
          <td>{{a.account_number}}</td>
          <td>{{a.description}}</td>
        </tr>
        <tr ng-repeat-end ng-repeat-start="sa in a.subacct">
          <td>{{sa.first_name}} {{sa.last_name}}</td>
          <td>{{sa.account_number}}</td>
          <td>{{sa.description}}</td>
        </tr>


这可行。但是这次数据包括第三级; subacct对象的键为subsubacct

[
 { "accountnum": 1,
   "name": "foo",
   "subacct": [
      { "accountnum": 1-1,
        "name": "bar",
        "subsubacct": [
        { "accountnum": 1-1-1,
          "name": "bar"
        } ...
      } ...
    ]
  } ...
]


因此,我尝试添加第三级,但未显示(没有控制台错误):

        <tr ng-repeat-start="a in cac.costAccounts">
          <td>{{a.first_name}} {{a.last_name}}</td>
          <td>{{a.account_number}}</td>
          <td>{{a.description}}</td>
        </tr>
        <tr ng-repeat-end ng-repeat-start="sa in a.subacct">
          <td>{{sa.first_name}} {{sa.last_name}}</td>
          <td>{{sa.account_number}}</td>
          <td>{{sa.description}}</td>
        </tr>
        <tr ng-repeat-end ng-repeat="ssa in sa.subsubacct">
          <td>{{ssa.first_name}} {{ssa.last_name}}</td>
          <td>{{ssa.account_number}}</td>
          <td>{{ssa.description}}</td>
        </tr>


那么如何获得第三个循环?

最佳答案

一种解决方案是使用tbody

<tbody ng-repeat="a in cac.costAccounts">
    <tr>
      <td>{{a.first_name}} {{a.last_name}}</td>
      <td>{{a.account_number}}</td>
      <td>{{a.description}}</td>
    </tr>
    <tr ng-repeat-start="sa in a.subacct">
      <td>{{sa.first_name}} {{sa.last_name}}</td>
      <td>{{sa.account_number}}</td>
      <td>{{sa.description}}</td>
    </tr>
    <tr ng-repeat-end="ssa in sa.subsubacct">
      <td>{{ssa.first_name}} {{ssa.last_name}}</td>
      <td>{{ssa.account_number}}</td>
      <td>{{ssa.description}}</td>
    </tr>
</tbody>

08-19 15:57