Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUGFIX beta] Add special values to {{each}}'s keyPath. #11339

Merged
merged 1 commit into from
Jun 4, 2015

Conversation

rwjblue
Copy link
Member

@rwjblue rwjblue commented Jun 4, 2015

Adds the following special values:

  • @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).

Makes a couple fixes to allow numeric values from the provided path (many databases use auto-incrementing numbers as id's).

rwjblue added a commit that referenced this pull request Jun 4, 2015
[BUGFIX beta] Add special values to `{{each}}`'s keyPath.
@rwjblue rwjblue merged commit 0cdfa9d into emberjs:master Jun 4, 2015
@rwjblue rwjblue deleted the each-special-values branch June 4, 2015 13:08
@knownasilya
Copy link
Contributor

Sweetness! Great job @rwjblue

@ilkkao
Copy link
Contributor

ilkkao commented Jun 5, 2015

@rwjblue This logic should be added also here:

var key = keyPath ? get(item, keyPath) : String(i);

Noticed with this template. Not sure btw why legacy-each is used.

{{#each model key="windowId" as |window|}}
    {{foo-component content=window}}
{{else}}
   ...
{{/each}} 

In any case legacy each should support same special key values, otherwise it's too confusing. I can try to create a PR during the weekend if you like. Logic should be put to a separate module, not copy pasted?

@ilkkao
Copy link
Contributor

ilkkao commented Jun 5, 2015

PR here #11353

@rwjblue
Copy link
Member Author

rwjblue commented Jun 5, 2015

Thank you for the PR for this! I do not think the snippet above should be falling into the legacy each case though. Can you double check and open an issue if it is?

@ilkkao
Copy link
Contributor

ilkkao commented Jun 5, 2015

Right, I'll investigate more and report if it really happens.

@ilkkao
Copy link
Contributor

ilkkao commented Jun 6, 2015

@rwjblue In my case I was doing model=this on upper layer where this was ArrayController (I had forgot to convert it to Ember.Controller). All good.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants