zarm
zarm copied to clipboard
picker-view组件无法滚动的问题
Description
偶现: 二次封装picker-view组件后, 发现有时候wheel部分无法滚动
Steps to Reproduce
- 将picker-view所需级联数据异步多次加载
Error Trace (if possible)
better-scroll需要在页面渲染完成后创建 否则在数据加载完成前创建会导致高度计算错误
Solution
- 修改wheel组件
componentDidMount() {
setTimeout(() => { this.createBScroll() })
}
createBScroll = () => {
const value = getValue(this.props);
const { dataSource } = this.props;
const initIndex = this.getSelectedIndex(value, dataSource);
const wheel = { selectedIndex: initIndex, wheelWrapperClass: `wheel-content`, wheelItemClass: `wheel__item` }
this.BScroll = new BScroll(this.wrapper, { wheel, probeType: 3 });
this.props.disabled && this.BScroll.disable();
this.BScroll.on("scrollEnd", () => { this.handleScrollEnd() });
}
Environment
- zarm version: v2.9.2
- react/react-native version: 16.13.1
- system version: macos 11.2
- browser version: chrome 91.0.4472.114(正式版本) (x86_64)
You can get this information from package.json and your device.
将picker-view所需级联数据异步多次加载
请问下可以简单用代码描述下这个操作嘛?
将picker-view需要级联数据异步多个加载
好像下可以简单用代码描述下这个操作嘛?
for (let $i = 0; $i < cascade; $i++) {
const { value: previous } = this.state
const parent = previous[$i - 1] || undefined
const current: DATASOURCE = await requestOptions(name, parent, previous)
const options = this.state.options.map((e, i) => i === $i ? current : e)
const value = previous?.map((e, i) => (!e && i === $i) ? current[0]?.value : e)
await this.asyncSetState({ options, value })
}