Vue-Multiselect多重选择能够重新选择选定的项目
使用 vue-multiselect 启用了具有多个选择的库,是否可以重新选择选定的项目/s?假设有两个选项产品1和产品2:
options: [
{ name: 'Product 1', value: 'product_1' },
{ name: 'Product 2', value: 'product_2' }
]
然后我将多次选择产品1,因此结果是:
[
{
"name": "Product 1",
"value": "product_1"
},
{
"name": "Product 1",
"value": "product_1"
}
]
<
a href =“ https://i.sstatic.net/cxjv8.png “ rel =“ nofollow noreferrer”>
如何实现这种行为?
PS 我愿意使用其他VUE 3选择库,其中包含多个项目以及重复所选项目。
Using Vue-Multiselect library with multiple selections enabled, is it possible to reselect the selected item/s? Let's say there are two options Product 1 and Product 2:
options: [
{ name: 'Product 1', value: 'product_1' },
{ name: 'Product 2', value: 'product_2' }
]
Then I will select Product 1 multiple times so the result would be:
[
{
"name": "Product 1",
"value": "product_1"
},
{
"name": "Product 1",
"value": "product_1"
}
]
It would be something like:
How to achieve this behavior?
PS
I'm open to using other Vue 3 select libraries with multiple items and duplication of selected items.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
![扫码二维码加入Web技术交流群](/public/img/jiaqun_03.jpg)
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
AS @mamdasan 说,为了达到此要求,您可以收听
@input
事件,该事件在此后发出的事件V-Model
值更改。要获取重复的选定选项,您可以在收听@input
事件时保持单独的数组并清空V-Model变量。注意:我在处理此要求时面临一个挑战,就是将选择显示为
v-Model
“值”值空了。演示:
As @mamdasan said, To achieve this requirement you can listen to
@input
event which emitted afterv-model
value changes. To get the duplicate selected options you can maintain a separate array and empty the v-model variable while listening to@input
event.Note : I am facing one challenge while working on this requirement is to display the chips on selection as
v-model
value got empty.Demo :
首先聆听多选择V模型的更改,每次都会更改,将所选项目添加到数组中,然后清空多选择的V-Model对象。
然后在多选中添加此插槽:
基本上您创建一个数组
first listen for changes on your multiselect v-model, every time is changes, add the selected item to an array and empty the multiselect v-model object.
then add this slot in your multi-select:
basically you create an array, every time the user clicks on multiselect, you add to your array and empty the select value again, and then show the selected items to user