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

Can you use both split and unique, in that order? #386

Open
bryllyg opened this issue Jun 30, 2021 · 2 comments
Open

Can you use both split and unique, in that order? #386

bryllyg opened this issue Jun 30, 2021 · 2 comments

Comments

@bryllyg
Copy link

bryllyg commented Jun 30, 2021

Syntax and functionality question - The list I am querying has a field with multiple comma delimited values. I am trying to:

  • use #each go through all the items
  • split the my multiselect-choice field on the comma
  • then run through the split items and pull out only unique entries (I have to get unique after the split)

I can do one or the other, split the entry OR get unique, but I can't figure out a way to do both. Is it possible using the provided helpers?

I've tried variations using
{{#each items as |item|}}
{{#with {split fieldname ',') as |tag|}}
{{#each unique tag}}

Any suggestions? Thanks!

@Devilthehell
Copy link

Hey @bryllyg,

I do not have a field that contains multiple values separated by a comma, so I went ahead and plucked values out of a column to re create the scenario:

{{#each (unique (pluck DepartmentItems "Group"))}}{{.}},{{/each}}

Where "(pluck DepartmentItems "Group")" is the array of values that contain duplicates.
For your script, I would change

{{#with {split fieldname ',') as |tag|}}

to

{{#with (split fieldname ',') as |tag|}}

and

{{#each unique tag}}

to

{{#each (unique tag)}}{{.}},{{/each}}

Hope this helps.
Let me know if it does, or if I need to do something differently.
I didn't know about the ability of "as |item|" until now, but maybe it is just your system that allows it?

@bryllyg
Copy link
Author

bryllyg commented Aug 13, 2021

Thanks! I'll give it a go.

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

No branches or pull requests

2 participants