Skip to content

Commit

Permalink
fix:ChainedSelect针对后端接口返回内容不规范导致报错处理 (#4825)
Browse files Browse the repository at this point in the history
Co-authored-by: ”jiatianqi“ <”[email protected]“>
  • Loading branch information
jiatianqi and ”jiatianqi“ authored Jul 11, 2022
1 parent 1476606 commit a33a5d1
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
2 changes: 1 addition & 1 deletion docs/zh-CN/components/form/chain-select.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ order: 7
{
"name": "select3",
"type": "chained-select",
"label": "级联下拉",
"label": "链式下拉",
"source": "/api/mock2/options/chainedOptions?waitSeconds=1&parentId=$parentId&level=$level&maxLevel=4",
"value": "a,b"
}
Expand Down
13 changes: 9 additions & 4 deletions packages/amis/src/renderers/Form/ChainedSelect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {ActionObject} from 'amis-core';
import {FormOptionsSchema} from '../../Schema';

/**
* 级联选择框
* 链式下拉框
* 文档:https://baidu.gitee.io/amis/docs/components/form/chained-select
*/
export interface ChainedSelectControlSchema extends FormOptionsSchema {
Expand Down Expand Up @@ -167,7 +167,12 @@ export default class ChainedSelectControl extends React.Component<

const stack = this.state.stack.concat();
const remoteValue = ret.data ? ret.data.value : undefined;
let options = (ret.data && (ret.data as any).options) || ret.data;
let options =
ret?.data?.options ||
ret?.data?.items ||
ret?.data?.rows ||
ret.data ||
[];

stack.splice(idx, stack.length - idx);

Expand Down Expand Up @@ -287,7 +292,7 @@ export default class ChainedSelectControl extends React.Component<
}
classPrefix={ns}
key="base"
options={options}
options={Array.isArray(options) ? options : []}
value={arr[0]}
onChange={this.handleChange.bind(this, 0)}
loading={loading}
Expand All @@ -306,7 +311,7 @@ export default class ChainedSelectControl extends React.Component<
}
classPrefix={ns}
key={`x-${index + 1}`}
options={options}
options={Array.isArray(options) ? options : []}
value={arr[index + 1]}
onChange={this.handleChange.bind(this, index + 1)}
loading={loading}
Expand Down

0 comments on commit a33a5d1

Please sign in to comment.