[bugfix] Area: error when list empty (#661)

This commit is contained in:
neverland 2018-09-28 11:50:48 +08:00 committed by GitHub
parent 677a980c15
commit b8fb181b66
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 36 additions and 3769 deletions

File diff suppressed because it is too large Load Diff

View File

@ -1,11 +1,24 @@
import Page from '../../common/page';
import AreaList from './area';
Page({
data: {
areaList: AreaList,
areaList: {},
loading: true,
value: 330302
},
onShow() {
wx.request({
url: 'https://cashier.youzan.com/pay/wsctrade/order/buy/getAllRegion.json',
success: response => {
this.setData({
loading: false,
areaList: response.data.data
});
}
});
},
onChange(event) {
console.log(event);
}

View File

@ -1,11 +1,25 @@
<demo-block title="基础用法">
<van-area area-list="{{ areaList }}" />
<van-area
loading="{{ loading }}"
area-list="{{ areaList }}"
/>
</demo-block>
<demo-block title="选中省市县">
<van-area area-list="{{ areaList }}" value="{{ value }}" />
<van-area
value="{{ value }}"
loading="{{ loading }}"
area-list="{{ areaList }}"
/>
</demo-block>
<demo-block title="配置显示列">
<van-area area-list="{{ areaList }}" columns-num="{{ 2 }}" title="标题" bind:confirm="onChange" bind:change="onChange" />
<van-area
title="标题"
columns-num="{{ 2 }}"
loading="{{ loading }}"
area-list="{{ areaList }}"
bind:change="onChange"
bind:confirm="onChange"
/>
</demo-block>

View File

@ -68,13 +68,13 @@ VantComponent({
const { value } = event.detail;
const { pickerValue, displayColumns } = this.data;
const index = pickerValue.findIndex((item, index) => item !== value[index]);
const values = displayColumns[index];
// 没有变更 或 选中项序号小于0 不处理
if (index < 0 || value[index] < 0) {
if (!value[index] || !values[value[index]]) {
return;
}
const values = displayColumns[index];
this.code = values[value[index]].code;
this.setValues();
this.$emit('change', {
@ -118,7 +118,7 @@ VantComponent({
},
setValues() {
let code = this.code || Object.keys(this.data.areaList.county_list)[0] || '';
let code = this.code || Object.keys(this.data.areaList.county_list || {})[0] || '';
const province = this.getList('province');
const city = this.getList('city', code.slice(0, 2));