In Ember 1.13 and later what key should I use with each when iterating over an array of strings?

拜拜、爱过 提交于 2019-12-04 22:43:44
artych

UPDATE (Jun,18) In Ember 1.13.2 default key="@identity" is used, to prevent users from having to specify a key= to each {{each}} invocation.

@guid and @item are deprecated in favor of the new default.

https://github.com/emberjs/ember.js/releases/tag/v1.13.2 https://github.com/emberjs/ember.js/pull/11461

================= Answer for Ember 1.13, 1.13.1 =========

You could use key="@index" or key="@item".

There are a few special values for key ( docs ):

  • @index - The index of the item in the array.
  • @item - The item in the array itself. This can only be used for arrays of strings or numbers.
  • @guid - Generate a unique identifier for each object (uses Ember.guidFor).

    {{#each widgetNames key="@index" as |widgetName|}}
       {{component widgetName removeWidget="removeWidget"}}
    {{/each}}
    
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!