[bugfix] Area: 修复getIndexes结果不符合预期

修复 #1212
This commit is contained in:
rex 2019-01-19 18:51:15 +08:00 committed by GitHub
parent 03fa90dd9d
commit d3e29b7cbc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 29 additions and 21 deletions

View File

@ -75,11 +75,12 @@ VantComponent({
onChange(event: Weapp.Event) { onChange(event: Weapp.Event) {
const { index, picker, value } = event.detail; const { index, picker, value } = event.detail;
this.code = value[index].code; this.code = value[index].code;
this.setValues(); this.setValues().then(() => {
this.$emit('change', { this.$emit('change', {
picker, picker,
values: picker.getValues(), values: picker.getValues(),
index index
});
}); });
}, },

View File

@ -100,10 +100,12 @@ VantComponent({
// set column value by index // set column value by index
setColumnValue(index: number, value: any) { setColumnValue(index: number, value: any) {
const column = this.getColumn(index); const column = this.getColumn(index);
if (column) {
return column.setValue(value); if (column == null) {
return Promise.reject('setColumnValue: 对应列不存在');
} }
return Promise.reject('setColumnValue: 对应列不存在');
return column.setValue(value);
}, },
// get column option index by column index // get column option index by column index
@ -114,10 +116,12 @@ VantComponent({
// set column option index by column index // set column option index by column index
setColumnIndex(columnIndex: number, optionIndex: number) { setColumnIndex(columnIndex: number, optionIndex: number) {
const column = this.getColumn(columnIndex); const column = this.getColumn(columnIndex);
if (column) {
return column.setIndex(optionIndex); if (column == null) {
return Promise.reject('setColumnIndex: 对应列不存在');
} }
return Promise.reject('setColumnIndex: 对应列不存在');
return column.setIndex(optionIndex);
}, },
// get options of column by index // get options of column by index
@ -129,18 +133,21 @@ VantComponent({
setColumnValues(index: number, options: any[], needReset = true) { setColumnValues(index: number, options: any[], needReset = true) {
const column = this.children[index]; const column = this.children[index];
if ( if (column == null) {
column && return Promise.reject('setColumnValues: 对应列不存在');
JSON.stringify(column.data.options) !== JSON.stringify(options)
) {
return column.set({ options }).then(() => {
if (needReset) {
column.setIndex(0);
}
});
} }
return Promise.reject('setColumnValues: 对应列不存在'); const isSame = JSON.stringify(column.data.options) === JSON.stringify(options);
if (isSame) {
return Promise.resolve();
}
return column.set({ options }).then(() => {
if (needReset) {
column.setIndex(0);
}
});
}, },
// get values of all columns // get values of all columns