This commit is contained in:
梁灏 2017-05-18 18:23:39 +08:00
parent a28bc982af
commit 933afc7a2c
3 changed files with 210 additions and 115 deletions

View file

@ -128,7 +128,9 @@
tmpSelected: [],
updatingValue: false, // to fix set value in changeOnSelect type
currentValue: this.value,
query: ''
query: '',
validDataStr: '',
isLoadedChildren: false // #950
};
},
computed: {
@ -270,9 +272,31 @@
},
handleFocus () {
this.$refs.input.focus();
},
// loading data updateSelect
getValidData (data) {
function deleteData (item) {
const new_item = Object.assign({}, item);
if ('loading' in new_item) {
delete new_item.loading;
}
if ('__value' in new_item) {
delete new_item.__value;
}
if ('__label' in new_item) {
delete new_item.__label;
}
if ('children' in new_item && new_item.children.length) {
new_item.children = new_item.children.map(i => deleteData(i));
}
return new_item;
}
return data.map(item => deleteData(item));
}
},
created () {
this.validDataStr = JSON.stringify(this.getValidData(this.data));
this.$on('on-result-change', (params) => {
// lastValue: is click the final val
// fromInit: is this emit from update value
@ -332,7 +356,14 @@
data: {
deep: true,
handler () {
this.$nextTick(() => this.updateSelected());
const validDataStr = JSON.stringify(this.getValidData(this.data));
if (validDataStr !== this.validDataStr) {
this.validDataStr = validDataStr;
if (!this.isLoadedChildren) {
this.$nextTick(() => this.updateSelected());
}
this.isLoadedChildren = false;
}
}
}
}

View file

@ -61,6 +61,7 @@
const cascader = findComponentUpward(this, 'Cascader');
if (cascader && cascader.loadData) {
cascader.loadData(item, () => {
cascader.isLoadedChildren = true;
this.handleTriggerItem(item);
});
return;