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

2016-11-02 11:57发布

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.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里面清空一次,该如何做?

1条回答
无极 - 这个人很懒,什么都没留下
1楼 · 2016-11-02 12:10.采纳回答

用回调啊。

一周热门 更多>