naive-ui
naive-ui copied to clipboard
Allow SelectOption.value to be of any type
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 }))
could be usefule, kinda like the vuetify api https://v2.vuetifyjs.com/en/api/v-select/#props-return-object
Still believe this would be very useful.
请确认新版中是否已解决,如果仍未解决,请重新开启一个新的 issue,以帮助我们更快的关注到