优艾设计网

react 因为this.setState是异步生效的,我想要通过this.setState来赋予控 财富值81?

onChange(key) { let detailData = []; let TimelineChild = []; const orderCodeData = { orderCode: key, }; const self = this; self.setState({ itemList:[], }) callGetDetailLogMemoFn(orderCodeData).then((res) => { detailData = res.data; detailData.map((item) => { const detailDataGmtCreate = item.gmtCreate; const detailDataLogMemo = item.logMemo; const reg = /u5931u8D25/g; const regBeyond = /u8d85u65f6/g; const regs = reg.test(detailDataLogMemo); const regBeyonds = regBeyond.test(detailDataLogMemo); if (regs || regBeyonds) { if (detailDataLogMemo !== null && detailDataLogMemo.length >= 64) { TimelineChild.push( <Timeline.Item color="red" key={item.id}> {detailDataGmtCreate} - {detailDataLogMemo.substring(0, 50)} <Button type="primary" size="small" onClick={this.handleDetail.bind(this, detailDataLogMemo)}>详情</Button> </Timeline.Item> ) } else { TimelineChild.push( <Tooltip placement="topRight" arrowPointAtCenter key={item.id} title={detailDataLogMemo}> <Timeline.Item color="red" key={item.id}> {detailDataGmtCreate} - {detailDataLogMemo.substring(0, 50)} </Timeline.Item> </Tooltip> ) } } else { if (detailDataLogMemo !== null && detailDataLogMemo.length >= 64) { TimelineChild.push( <Timeline优艾设计网_PS问答.Item key={item.id}> {detailDataGmtCreate} - {detailDataLogMemo.substring(0, 50)} <Button type="primary" size="small" onClick={this.handleDetail.bind(this, detailDataLogMemo)}>详情</Button> </Timeline.Item> ) } else { TimelineChild.push( <Tooltip placement="topRight" arrowPointAtCenter key={item.id} title={detailDataLogMemo}> <Timeline.Item key={item.id}> {detailDataGmtCreate} - {detailDataLogMemo.substring(0, 50)} </Timeline.Item> </Tooltip> ) } } self.setState({ itemList: <Timeline>{TimelineChild}</Timeline> }) }) }); }

我是用的antd的折叠面板组件,在onChange事件中,我将数据进行遍历放进了数组中,然后渲染出来,现在我想要使用this.setState在刚刚触发onChange事件,还没有开始处理数据之前先将TimelineChild里面清空一次,该如何做?


meizhouliyu 2022-09-13 10:20

优艾设计网_Photoshop交流

上面代码取自这篇文章的里: https://medium.com/@mweststra...


360U2760100377 2022-09-13 10:34

优艾设计网_Photoshop交流

用回调啊。


0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜