pull/9/head
tangjinzhou 2018-02-23 11:28:43 +08:00
parent d3c374c900
commit 4669e50827
2 changed files with 25 additions and 17 deletions

View File

@ -75,8 +75,10 @@ export default {
// onInputKeydown: noop, // onInputKeydown: noop,
}, },
data () { data () {
this.labelMap = new Map()
this.titleMap = new Map()
let sValue = [] let sValue = []
const { value, defaultValue, combobox, open, defaultOpen, $slots } = this const { value, defaultValue, combobox, open, defaultOpen } = this
if (hasProp(this, 'value')) { if (hasProp(this, 'value')) {
sValue = toArray(value) sValue = toArray(value)
} else { } else {
@ -93,9 +95,7 @@ export default {
} }
}) })
} }
this.labelMap = new Map() this.initLabelAndTitleMap(sValue)
this.titleMap = new Map()
this.updateLabelAndTitleMap($slots.default)
let inputValue = '' let inputValue = ''
if (combobox) { if (combobox) {
inputValue = sValue.length inputValue = sValue.length
@ -175,6 +175,24 @@ export default {
} }
}, },
methods: { methods: {
initLabelAndTitleMap (sValue) {
// label and title
const labelArr = []
const titleArr = []
const values = sValue || this.sValue
values.forEach((val) => {
const key = val.key
let { label, title } = val
label = label === undefined ? this.labelMap.get(key) : label
title = title === undefined ? this.titleMap.get(key) : title
labelArr.push([key, label === undefined ? key : label])
titleArr.push([key, title])
})
this.labelMap = new Map(labelArr)
this.titleMap = new Map(titleArr)
this.updateLabelAndTitleMap(this.$slots.default)
},
updateLabelAndTitleMap (children = []) { updateLabelAndTitleMap (children = []) {
children.forEach(child => { children.forEach(child => {
if (!child) { if (!child) {
@ -1431,17 +1449,7 @@ export default {
}, },
render () { render () {
// label and title this.initLabelAndTitleMap()
const labelArr = []
const titleArr = []
this.sValue.forEach(({ key }) => {
labelArr.push([key, this.labelMap.get(key)])
titleArr.push([key, this.titleMap.get(key)])
})
this.labelMap = new Map(labelArr)
this.titleMap = new Map(titleArr)
this.updateLabelAndTitleMap(this.$slots.default)
const props = this.$props const props = this.$props
const multiple = isMultipleOrTags(props) const multiple = isMultipleOrTags(props)
const preOptions = this._options || [] const preOptions = this._options || []

View File

@ -6,7 +6,7 @@ export default {
data () { data () {
return { return {
destroy: false, destroy: false,
value: String(9), value: 9,
} }
}, },
methods: { methods: {
@ -71,7 +71,7 @@ export default {
<Option value='21' disabled text='disabled'>disabled</Option> <Option value='21' disabled text='disabled'>disabled</Option>
<Option value='31' text='yiminghe'>yiminghe</Option> <Option value='31' text='yiminghe'>yiminghe</Option>
{[0, 1, 2, 3, 4, 5, 6, 7, 8, 9].map((i) => { {[0, 1, 2, 3, 4, 5, 6, 7, 8, 9].map((i) => {
return <Option key={String(i)} text={String(i)}>{i}</Option> return <Option key={i} text={String(i)}>{i}</Option>
})} })}
</Select> </Select>
</div> </div>