【发布时间】:2015-08-31 02:06:00
【问题描述】:
在_onChange 方法中,我等待this.state.name 的更改。关于更改_updateArticle方法被调用:
_onChange() {
var team = this.getTeamState();
this.setState({name: team});
console.log(this.state.name); //"Boston Celtics" //this should have changed but it didn't
this.unbind("articles");
this._updateArticle();
},
然后在 _updateArticle 中使用这个新状态创建一个新引用。
_updateArticle(team) {
var teamRef = new Firebase(this.props.baseUrl + team + "/results");
console.log(this.state.team); // "Boston Celtics" //this should have been new but its not
this.bindAsArray(teamRef, 'articles');
},
在render 方法中只是为了检查我把console.log 放在检查的状态。在render,this.state.name 已正确更新。我的问题是为什么this.state 在render 函数之外是不同的?。
【问题讨论】:
标签: javascript reactjs reactjs-flux react-jsx