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

How to get the object of selected option? #1189

Closed
rodrigoslayertech opened this issue Nov 27, 2017 · 2 comments
Closed

How to get the object of selected option? #1189

rodrigoslayertech opened this issue Nov 27, 2017 · 2 comments

Comments

@rodrigoslayertech
Copy link
Contributor

In the example below:

...
<q-select color="secondary" v-model="select" :options="listOptions" />
...
select: 'fb',
listOptions: [
        {
          label: 'Google',
          icon: 'email',
          value: 'goog'
        },
        {
          label: 'Facebook',
          icon: 'chat',
          description: 'Enables communication',
          value: 'fb'
        },
        {
          label: 'Twitter',
          inset: true,
          rightIcon: 'live_help',
          value: 'twtr'
        },
        {
          label: 'Apple Inc.',
          inset: true,
          stamp: '10 min',
          value: 'appl'
        },
        {
          label: 'Oracle',
          description: 'Some Java for today?',
          icon: 'unarchive',
          rightIcon: 'widgets',
          value: 'ora'
        }
      ]
...

If the user select Oracle, how to get the other properties like label, icon and description, etc...?
The selection property should store the entire object, not just the value.

@rodrigoslayertech rodrigoslayertech changed the title How to get the object of select options? How to get the object of selected options? Nov 27, 2017
@rodrigoslayertech rodrigoslayertech changed the title How to get the object of selected options? How to get the object of selected option? Nov 27, 2017
@pdanpdan
Copy link
Collaborator

Selection property keeps what's in the value - if you need to have an object as selection put an object in value.
All the other properties are for presentation.

@rstoenescu
Copy link
Member

Based on the value, just use listOptions.find(opt => opt.value === value)

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

3 participants