How to send key in vue multiselect plugin? Check my code:
<multiselect v-model="form.docTypeIds" :options="docTypes" :multiple="true" placeholder="All" track-by="l" label="l"></multiselect>
docTypes is array like:
{
"k": 19,
"l": "test1"
}, {
"k": 53,
"l": "test2"
},
Right now i send object like this:
{
k: 19,
l: "testtest"
}, {
k: 53,
l: "testteste2"
}
I need to send only k and 19, 53
I need to send this:
[19,53]
Also i need to send if noting is selected i need to send
-1
Instead of using v-model
, use value
and @change
:value="form.docTypeIds"
And a @change
hander:
@select="handleMultiSelection"
Then add the method that reduces
the values into an array of ids
:
handleMultiSelection (values) {
this.form.docTypeIds = values.reduce((carry, obj) => {
return obj.k
}, [])
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.