Skip to content

Commit

Permalink
fix ant-design#412 and picker demo (ant-design#459)
Browse files Browse the repository at this point in the history
  • Loading branch information
JackClown authored and BANG88 committed Apr 20, 2019
1 parent 95a8733 commit 173ff11
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 12 deletions.
35 changes: 26 additions & 9 deletions components/picker/cascader/Cascader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import arrayTreeFilter from 'array-tree-filter';
import React from 'react';
import MultiPicker from '../MultiPicker';
import Picker from '../Picker';
import { CascaderProps } from './CascaderTypes';
import { CascaderDataItem, CascaderProps } from './CascaderTypes';

class Cascader extends React.Component<CascaderProps, any> {
static defaultProps = {
Expand Down Expand Up @@ -53,17 +53,34 @@ class Cascader extends React.Component<CascaderProps, any> {

getValue(d: any, val: any) {
let data = d || this.props.data;
let value = val || this.props.value || this.props.defaultValue;
if (!value || !value.length || value.indexOf(undefined) > -1) {
value = [];
for (let i = 0; i < this.props.cols!; i++) {
if (data && data.length) {
value[i] = data[0].value;
data = data[0].children;
const value = val || this.props.value || this.props.defaultValue;
let level = 0;
const nextValue = [];

if (value && value.length) {
do {
const index = (data as CascaderDataItem[]).findIndex(item => item.value === value[level]);

if (index < 0) {
break;
}

nextValue[level] = value[level];
level += 1;
data = data[index].children || [];
} while (data.length > 0);
}

for (let i = level; i < this.props.cols!; i++) {
if (data && data.length) {
nextValue[i] = data[0].value;
data = data[0].children;
} else {
break;
}
}
return value;

return nextValue;
}

getCols() {
Expand Down
4 changes: 1 addition & 3 deletions components/picker/demo/basic.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,7 @@ export default class PopupExample extends React.Component<any, any> {
value={this.state.value}
onChange={this.onChange}
>
<List.Item arrow="horizontal" onPress={this.onPress}>
省市选择
</List.Item>
<List.Item arrow="horizontal">省市选择</List.Item>
</Picker>
<Picker
data={this.state.data}
Expand Down

0 comments on commit 173ff11

Please sign in to comment.