【问题标题】:Is there an equivalent of Rails' each_with_index in an Angular directive?在 Angular 指令中是否有相当于 Rails 的 each_with_index 的东西?
【发布时间】:2014-05-02 09:32:23
【问题描述】:

假设我在 Angular 中有这样的代码:

<ul>
  <li ng-repeat="person in people">
    {{person.name}}
  </li>
</ul>

引用这样的模型:

[
  {name: "Dave"},
  {name: "Martha"}
]

是否可以生成这样的 DOM,其中 id 是人员的数组索引?:

<ul>
  <li id="person_1>
    Dave
  </li>
  <li id="person_2>
    Martha
  </li>
</ul>

【问题讨论】:

    标签: javascript ruby-on-rails angularjs


    【解决方案1】:

    您可以使用ng-repeat$index 属性。

    例如

    <ul>
      <li ng-repeat="person in people" id="person_{{$index + 1}}">
        {{person.name}}
      </li>
    </ul>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-11-18
      • 2016-06-03
      • 1970-01-01
      • 2023-03-23
      • 2011-06-19
      • 2015-09-02
      • 1970-01-01
      相关资源
      最近更新 更多