我怀疑我还不能用谷歌搜索,但我有这个反应组件,我想使用 componentWillMount() 方法使用回流存储更新它的状态。
我能够更新商店中的状态,但是使用 this.trigger 从商店更新它的状态并没有给我更新的数据状态,这让我感到困惑。如何获取数据的更新状态。
这是我的组件目前的样子
var Challenges = React.createClass({
contextTypes: {
router: React.PropTypes.func
},
mixins: [Reflux.connect(ChallengeStore,'challenges')],
getInitialState: function() {
return {
challenges: []
}
}
componentDidMount: function() {
var trackId = this.props.params.trackId; // the url
ChallengeActions.GetChallenges(trackId);
console.log(this.state);
},
render: function () {
return(
<div>
<h1>{ this.state.challenges.title }</h1> <List challenges={ this.state.challenges } />
</div>
);
}
});
还有我的店在这里
var ChallengeStore = Reflux.createStore({
listenables: ChallengeActions,
onGetChallenges: function(url) {
var items = ChallengeService.getChallenges(url);
this.trigger({
challenges: items
});
}
});