react的this.setState中的有兩個。
1、this.setState異步的,不能用同步的思維討論問題
2、在進行組件通訊的回調的時候,this指向子組件,沒有指向父親這,怎么辦呢。在
class gradingView extends React.Component { constructor(...args) { super(...args); this.state = { suffixIcon: <Icon type="up" />, popDivShow:false, popImage:jdSelectUp }; window.that=this; }
在這里面將that
還有一種方案。
在回調函數中寫
onSelectedItem=(item)=>{ var that=this; that.setState({currentItem:item},function(){ that.fetchData(0); }); }
為什么這樣寫呢,因為這里是es6的開發環境,與編譯器有關。