naive-ui icon indicating copy to clipboard operation
naive-ui copied to clipboard

Allow SelectOption.value to be of any type

Open MrRawbin opened this issue 2 years ago • 2 comments

This function solves the problem (这个功能解决的问题)

Often when using a select menu, it is desirable to be able select any kind of value from a list of options. Currently, the only available options are string and number.

Consider a list of people:

const people: Array<Person> = [
  { id: 1, name: 'John Doe', age: 24 },
  { id: 2, name: 'Jane Doe', age: 25 },
]

In this case, we would have to use the id of the person as SelectOption value. When we select a user and want to do something with it, we then have to traverse the list of people and find the selected one by id, which is inefficient and leads to boilerplate code.

Expected API (期望的 API)

Using the people example above:

const selectOptions = people.map((person: Person) => ({ label: person.name, value: person }))

MrRawbin avatar Nov 16 '23 11:11 MrRawbin

could be usefule, kinda like the vuetify api https://v2.vuetifyjs.com/en/api/v-select/#props-return-object

realByg avatar Nov 24 '23 01:11 realByg

Still believe this would be very useful.

MrRawbin avatar Jun 12 '24 11:06 MrRawbin

请确认新版中是否已解决,如果仍未解决,请重新开启一个新的 issue,以帮助我们更快的关注到

jahnli avatar Sep 15 '25 12:09 jahnli