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

2016-11-02 14:32发布

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

友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
2条回答

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

一周热门 更多>