This commit is contained in:
梁灏 2017-05-18 16:01:53 +08:00
parent 3842df9abe
commit ddc35c9aaa
2 changed files with 30 additions and 3 deletions

View file

@ -2,7 +2,7 @@
<Row>
<i-col span="4">{{model}}</i-col>
<i-col span="8">
<i-select v-model="model" @input="handleInput" filterable remote :remote-method="remoteMethod" :loading="loading" clearable>
<i-select v-model="model" :label="['L Alabama', 'L Hawaii']" multiple @input="handleInput" filterable remote :remote-method="remoteMethod" :loading="loading" clearable>
<i-option v-for="option in options" :value="option.value" :key="new Date()">{{option.label}}</i-option>
</i-select>
</i-col>
@ -13,7 +13,8 @@
export default {
data () {
return {
model: '',
// model: 'Alabama',
model: ['Alabama', 'Hawaii'],
options: [
],
@ -74,6 +75,7 @@
]
},
remoteMethod (query) {
console.log(13)
if (query !== '') {
this.loading = true;
setTimeout(() => {

View file

@ -53,6 +53,10 @@
type: [String, Number, Array],
default: ''
},
label: {
type: [String, Number, Array],
default: ''
},
multiple: {
type: Boolean,
default: false
@ -303,7 +307,6 @@
},
updateMultipleSelected (init = false, slot = false) {
if (this.multiple && Array.isArray(this.model)) {
// todo label
let selected = this.remote ? this.selectedMultiple : [];
for (let i = 0; i < this.model.length; i++) {
@ -584,6 +587,23 @@
},
mounted () {
this.modelToQuery();
// remote
if (this.remote) {
if (!this.multiple && this.model !== '') {
this.selectToChangeQuery = true;
if (this.label === '') this.label = this.model;
this.lastQuery = this.label;
this.query = this.label;
} else if (this.multiple && this.model.length) {
if (this.label.length !== this.model.length) this.label = this.model;
this.selectedMultiple = this.model.map((item, index) => {
return {
value: item,
label: this.label[index]
};
});
}
}
this.$nextTick(() => {
this.broadcastQuery('');
});
@ -687,6 +707,11 @@
this.findChild(child => {
child.selected = this.multiple ? this.model.indexOf(child.value) > -1 : this.model === child.value;
});
// remote
const options = this.$slots.default || [];
if (this.query !== '' && !options.length) {
this.remoteMethod(this.query);
}
}
}
this.broadcast('Drop', 'on-update-popper');