Skip to content

Commit

Permalink
select multiple mode support default value (wmfe#63)
Browse files Browse the repository at this point in the history
  • Loading branch information
yueyao authored and clancyz committed Nov 7, 2016
1 parent aecb012 commit cca3732
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 7 deletions.
24 changes: 21 additions & 3 deletions src/components/select/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,22 @@
}
if (this.multiple) {
if (typeof option === 'object') {
return this.value.indexOf(option) > -1;
let value = option.label;
if (this.label && option[this.label]) {
value = option[this.label];
}
let isMatched = false;
let valueLen = this.value.length;
for (let i = 0; i < valueLen; i++) {
if (typeof this.value[i] === 'string') {
// if string mean defaultValue set
if (value === this.value[i]) {
isMatched = true;
this.value[i] = option;
}
}
}
return this.value.indexOf(option) > -1 || isMatched;
}
return this.value.indexOf(option) > -1;
}
Expand Down Expand Up @@ -395,7 +410,7 @@
},
getDropDownHeight() {
let list = this.$els.list;
let item = list.children[0];
let item = list.children[0] || null;
let itemHeight = item.currentStyle ? item.currentStyle.height : getComputedStyle(item, false).height;
let listHeight = list.currentStyle ? list.currentStyle.height : getComputedStyle(list, false).height;
return {
Expand All @@ -407,8 +422,11 @@
let me = this;
let selected = this.selected;
let indexs = [];
if (!this.options) {
return indexs;
}
this.options.forEach((item, index) => {
item.options.forEach((subItem, subIndex) => {
item.options && item.options.forEach((subItem, subIndex) => {
if (typeof subItem === 'string' && selected === subItem) {
indexs = [index, subIndex];
return;
Expand Down
16 changes: 12 additions & 4 deletions src/demos/select.vue
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@
<xcui-select class-name="select-demo"
placeholder="选择多个"
multiple
:selected="multipleDefaultValue"
@change="multipleObjectOnChange"
@remove="multipleObjectOnRemove"
:options="multipleObjOptions">
Expand All @@ -143,6 +144,10 @@
| :options | Array |无|默认数据,optgroup模式下数据结构有要求(具体查看demo#option Group) | 是|
| :disabled | Boolean | false | 禁用 | 否 |
| :selected | String | 无 | 默认已选的值 |否|
## Events

| 名字 | 类型 | 默认 | 描述 | 是否必选 |
|-----|-----|-----|-----|----|
| @change | function(value) / function(value,groupIndex,valueIndex) | 无 | 值发生变化的时候(2种模式: 普通模式/分组模式) | 否|
| @select | function(value) / function(value,groupIndex,valueIndex) | 无 | 发生了选择的时候(2种模式: 普通模式/分组模式)|否|
| @searchChange | function(searchValue) | 无 | 搜索值发生变化的时候 | 否
Expand Down Expand Up @@ -347,18 +352,21 @@
{
name: '1',
label: '1',
disabled: true
disable: false
}, {
name: '2',
label: '2',
disabled: true
disable: false
}, {
name: '3',
label: '3',
disabled: true
disable: false
}
],
multipleDefaultValue: [],
multipleDefaultValue: [
'3',
'2'
],
multipleDefaultValue2: [
2,
4
Expand Down

0 comments on commit cca3732

Please sign in to comment.