mirror of https://github.com/ElemeFE/element
switch itemSelected into a computed property
parent
139a30745c
commit
919f74b3b8
|
@ -4,7 +4,7 @@
|
||||||
@click.stop="selectOptionClick"
|
@click.stop="selectOptionClick"
|
||||||
class="el-select-dropdown__item"
|
class="el-select-dropdown__item"
|
||||||
v-show="queryPassed"
|
v-show="queryPassed"
|
||||||
:class="{ 'selected': itemSelected(), 'is-disabled': disabled, 'hover': parent.hoverIndex === index }">
|
:class="{ 'selected': itemSelected, 'is-disabled': disabled, 'hover': parent.hoverIndex === index }">
|
||||||
<slot>
|
<slot>
|
||||||
<span>{{ label }}</span>
|
<span>{{ label }}</span>
|
||||||
</slot>
|
</slot>
|
||||||
|
@ -13,7 +13,6 @@
|
||||||
|
|
||||||
<script type="text/babel">
|
<script type="text/babel">
|
||||||
import emitter from 'main/mixins/emitter';
|
import emitter from 'main/mixins/emitter';
|
||||||
const toString = Object.prototype.toString;
|
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
mixins: [emitter],
|
mixins: [emitter],
|
||||||
|
@ -39,7 +38,6 @@
|
||||||
|
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
parent: null,
|
|
||||||
index: -1,
|
index: -1,
|
||||||
queryPassed: true,
|
queryPassed: true,
|
||||||
hitState: false
|
hitState: false
|
||||||
|
@ -47,8 +45,24 @@
|
||||||
},
|
},
|
||||||
|
|
||||||
computed: {
|
computed: {
|
||||||
|
parent() {
|
||||||
|
let result = this.$parent;
|
||||||
|
while (!result.isSelect) {
|
||||||
|
result = result.$parent;
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
},
|
||||||
|
|
||||||
|
itemSelected() {
|
||||||
|
if (Object.prototype.toString.call(this.parent.selected) === '[object Object]') {
|
||||||
|
return this === this.parent.selected;
|
||||||
|
} else if (Array.isArray(this.parent.selected)) {
|
||||||
|
return this.parent.value.indexOf(this.value) > -1;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
currentSelected() {
|
currentSelected() {
|
||||||
return this.selected || (this.$parent.multiple ? this.$parent.value.indexOf(this.value) > -1 : this.$parent.value === this.value);
|
return this.selected || (this.parent.multiple ? this.parent.value.indexOf(this.value) > -1 : this.parent.value === this.value);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -77,14 +91,6 @@
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
itemSelected() {
|
|
||||||
if (toString.call(this.parent.selected) === '[object Object]') {
|
|
||||||
return this === this.parent.selected;
|
|
||||||
} else if (toString.call(this.parent.selected) === '[object Array]') {
|
|
||||||
return this.parent.value.indexOf(this.value) > -1;
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
queryChange(query) {
|
queryChange(query) {
|
||||||
this.queryPassed = new RegExp(query, 'i').test(this.label);
|
this.queryPassed = new RegExp(query, 'i').test(this.label);
|
||||||
if (!this.queryPassed) {
|
if (!this.queryPassed) {
|
||||||
|
@ -100,10 +106,6 @@
|
||||||
},
|
},
|
||||||
|
|
||||||
created() {
|
created() {
|
||||||
this.parent = this.$parent;
|
|
||||||
while (!this.parent.isSelect) {
|
|
||||||
this.parent = this.parent.$parent;
|
|
||||||
}
|
|
||||||
this.label = this.label || ((typeof this.value === 'string' || typeof this.value === 'number') ? this.value : '');
|
this.label = this.label || ((typeof this.value === 'string' || typeof this.value === 'number') ? this.value : '');
|
||||||
this.parent.options.push(this);
|
this.parent.options.push(this);
|
||||||
this.parent.optionsCount++;
|
this.parent.optionsCount++;
|
||||||
|
|
Loading…
Reference in New Issue