Select: Fix tag show value or empty issue (17199) (#17396)

* Select: Fix tag show value or empty issue

* update docs
pull/16366/head^2
luckyCao 2019-11-12 15:33:34 +08:00 committed by Zhi Cun
parent 068b3ad1b0
commit 57e9007893
5 changed files with 10 additions and 5 deletions

View File

@ -453,7 +453,7 @@ Enter keywords and search data from server.
}, },
mounted() { mounted() {
this.list = this.states.map(item => { this.list = this.states.map(item => {
return { value: item, label: item }; return { value: `value:${item}`, label: `label:${item}` };
}); });
}, },
methods: { methods: {

View File

@ -457,7 +457,7 @@ Introduzca palabras y datos para buscar desde el servidor.
}, },
mounted() { mounted() {
this.list = this.states.map(item => { this.list = this.states.map(item => {
return { value: item, label: item }; return { value: `value:${item}`, label: `label:${item}` };
}); });
}, },
methods: { methods: {

View File

@ -453,7 +453,7 @@ Vous pouvez aller chercher les options sur le serveur de manière dynamique.
}, },
mounted() { mounted() {
this.list = this.states.map(item => { this.list = this.states.map(item => {
return { value: item, label: item }; return { value: `value:${item}`, label: `label:${item}` };
}); });
}, },
methods: { methods: {

View File

@ -448,7 +448,7 @@
}, },
mounted() { mounted() {
this.list = this.states.map(item => { this.list = this.states.map(item => {
return { value: item, label: item }; return { value: `value:${item}`, label: `label:${item}` };
}); });
}, },
methods: { methods: {

View File

@ -153,8 +153,13 @@
}, },
beforeDestroy() { beforeDestroy() {
const { selected, multiple } = this.select;
let selectedOptions = multiple ? selected : [selected];
let index = this.select.cachedOptions.indexOf(this); let index = this.select.cachedOptions.indexOf(this);
if (index > -1) { let selectedIndex = selectedOptions.indexOf(this);
// if option is not selected, remove it from cache
if (index > -1 && selectedIndex < 0) {
this.select.cachedOptions.splice(index, 1); this.select.cachedOptions.splice(index, 1);
} }
this.select.onOptionDestroy(this.select.options.indexOf(this)); this.select.onOptionDestroy(this.select.options.indexOf(this));