我正在使用Select2 Jquery绑定我的下拉列表,用于多个选择.我正在使用select2 jquery.
它工作正常,我可以绑定我的下拉列表但我需要从我的多值选择器中获取所选值.我正在寻找获取select2 Jquery支持的值的方法.它可能是一个函数获得选定的值.
我的下拉绑定代码
$(".leaderMultiSelctdropdown").select2( {
maximumSelectionSize: 4
});
Run Code Online (Sandbox Code Playgroud) 很多天我一直在寻找这个错误的答案.我尝试了很多替代品但没有任何效果
我需要选择多个值.当我选择多个值时,我的代码会挂起,但是当我使用单个选择时,它可以正常使用self.$emit('input', this.value).我需要的是选择多个值.
Select2.vue
<template>
<select multiple class="input-sm" :name="name">
<slot></slot>
</select>
</template>
<style src="select2/dist/css/select2.min.css"></style>
<style src="select2-bootstrap-theme/dist/select2-bootstrap.min.css"></style>
<script>
import Select2 from 'select2';
export default{
twoWay: true,
priority: 1000,
props: ['options', 'value', 'name'],
data(){
return{
msg: 'hello'
}
},
mounted(){
var self = this;
$(this.$el)
.select2({theme: "bootstrap", data: this.options})
.val(this.value)
.trigger('change')
.on('change', function () {
//self.$emit('input', this.value) //single select worked good
self.$emit('input', $(this).val()) // multiple select
})
},
watch: {
value: function (value) {
$(this.$el).val(value).trigger('change');
},
options: function (options) { …Run Code Online (Sandbox Code Playgroud)