mirror of
https://gitee.com/baidu/amis.git
synced 2024-12-15 09:21:13 +08:00
fix: 解决tree异步数据不渲染的问题 (#5980)
This commit is contained in:
parent
9d18904eef
commit
d7409498d4
@ -240,6 +240,7 @@ export class TreeSelector extends React.Component<
|
||||
};
|
||||
|
||||
this.syncUnFolded(props);
|
||||
this.flattenOptions(props, true);
|
||||
}
|
||||
|
||||
componentDidMount() {
|
||||
@ -247,8 +248,6 @@ export class TreeSelector extends React.Component<
|
||||
|
||||
// onRef只有渲染器的情况才会使用
|
||||
this.props.onRef?.(this);
|
||||
// 初始化
|
||||
this.flattenOptions();
|
||||
enableNodePath && this.expandLazyLoadNodes();
|
||||
}
|
||||
|
||||
@ -257,6 +256,7 @@ export class TreeSelector extends React.Component<
|
||||
|
||||
if (prevProps.options !== props.options) {
|
||||
this.syncUnFolded(props);
|
||||
this.flattenOptions(props);
|
||||
}
|
||||
|
||||
if (
|
||||
@ -326,7 +326,6 @@ export class TreeSelector extends React.Component<
|
||||
}
|
||||
});
|
||||
|
||||
this.flattenOptions();
|
||||
initFoldedLevel && this.forceUpdate();
|
||||
|
||||
return unfolded;
|
||||
@ -832,7 +831,10 @@ export class TreeSelector extends React.Component<
|
||||
/**
|
||||
* TODO: this.unfolded => reaction 更加合理
|
||||
*/
|
||||
flattenOptions(props?: TreeSelectorProps): void | Option[] {
|
||||
flattenOptions(
|
||||
props?: TreeSelectorProps,
|
||||
initial?: boolean
|
||||
): void | Option[] {
|
||||
let flattenedOptions: Option[] = [];
|
||||
|
||||
eachTree(
|
||||
@ -855,7 +857,7 @@ export class TreeSelector extends React.Component<
|
||||
}
|
||||
}
|
||||
);
|
||||
if (!this.state.flattenedOptions.length && flattenedOptions.length) {
|
||||
if (initial) {
|
||||
// 初始化
|
||||
this.state = {...this.state, flattenedOptions};
|
||||
} else {
|
||||
|
@ -317,7 +317,7 @@ exports[`Renderer:chained-select 1`] = `
|
||||
</span>
|
||||
<div
|
||||
class="cxd-PopOver cxd-Select-popover cxd-PopOver--leftBottomLeftTop"
|
||||
style="display: block; width: auto; left: 0px; top: 0px; position: relative;"
|
||||
style="display: block; width: 0px; left: 0px; top: 0px; position: relative;"
|
||||
theme="cxd"
|
||||
>
|
||||
<div
|
||||
|
@ -113,12 +113,11 @@ test('Renderer:chained-select', async () => {
|
||||
expect(getByText('C 3')).toBeInTheDocument();
|
||||
fireEvent.click(getByText('C 3'));
|
||||
|
||||
await wait(100);
|
||||
await waitFor(() => {
|
||||
expect(fetcher).toBeCalledTimes(5);
|
||||
});
|
||||
fireEvent.click(getByText('请选择'));
|
||||
expect(getByText('未找到任何结果')).toBeInTheDocument();
|
||||
|
||||
await waitFor(() => {
|
||||
expect(container).toMatchSnapshot();
|
||||
});
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user