【发布时间】:2019-03-13 07:55:32
【问题描述】:
此图片链接显示“报告至”下拉列表中的搜索框位置错误的问题。这个应用程序是用 Vuejs 编写的。
这里我使用 Select2 插件作为下拉菜单。 我需要在 vuejs 中解决这个问题。
图片链接:https://i.stack.imgur.com/j37e0.png
我正在尝试通过以下链接https://github.com/select2/select2/issues/4614 实现这一点
但是这个methods_resizeDropdown,_positionDropdown会抛出控制台错误。
var select2Instance = $(selectNode).data('select2');
select2Instance.on('results:message', function(params){
this.dropdown._resizeDropdown();
this.dropdown._positionDropdown();
});
这里下面的代码是应用程序中的select2组件。
<template>
<div class="single-select">
<select class="select2" :disabled="disabled" multiple="multiple" v-if="multiple">
<slot></slot>
</select>
<select class="select2" :disabled="disabled" v-else>
<slot></slot>
</select>
</div>
</template>
<script>
export default {
name: 'ob-select2',
props: {
disabled: Boolean,
options: Object,
value: [String, Array],
multiple: Boolean,
inModal: Boolean,
initialData:[Array]
},
computed: {
config() {
let o = this.options
Object.assign(o, {theme: "onblick"})
return o
},
el() {
return jquery(this.$el).find("select")
}
},
mounted() {
this.init()
},
watch: {
config(value) {
this.init()
},
initialData(){
if(this.initialData != undefined){
this.appendInitialData()
}
},
value(value) {
if(this.multiple) { // For multiple
value = value && value.length >= 0 ? value : []
var el = this.el.val() && this.el.val().length >= 0 ? this.el.val() : []
if ([...value].sort().join(",") != [...el].sort().join(",")) {
this.el.val(value).trigger('change')
}
} else { // For single
value = value ? value : ''
var el = this.el.val() ? this.el.val() : ''
if(value != el)
this.el.val(value).trigger('change')
}
}
},
methods: {
init() {
var vm = this
if(this.initialData != undefined){
this.appendInitialData()
}
vm.el
// init select2
.select2(vm.config)
.val(vm.value)
.trigger('change')
// emit event on change.
.on('change', function () {
vm.$emit('input', vm.el.val())
jquery('.select2-selection__rendered').removeAttr('title');
})
.on('select2:open',function(){
vm.$emit('select2-open')
})
.on('select2:close',function(){
vm.$emit('select2-close')
})
if (vm.inModal) {
vm.el.on('select2:open', function (e) {
jquery(".select2-container").addClass("in-overlay");
})
vm.el.on("select2:close", function (e) {
jquery(".select2-container").removeClass("in-overlay");
});
}
},
getSelect2Data() {
return this.el.select2('data')
},
appendInitialData(){
if(this.initialData.length != 0){
this.initialData.forEach((a)=>{
let newOption = new Option(a.text,a.id,true,true)
this.el.append(newOption).trigger('change')
})
}
}
}
}
</script>
如何使用 vuejs 解决此问题。我正在使用单选下拉菜单,下拉选项将来自 ajax 调用。
【问题讨论】:
标签: javascript c# jquery vue.js