我的根组件中有这样的render()方法:
render: function() {
return (
<div className="question">
<QuestionA question={this.props.question} author={this.props.author}/>
<QuestionB yes={this.state.yes} no={this.state.no} />
<div className="question-side-switcher" onClick={this.handleSideChanging}></div>
</div>
);
}
Run Code Online (Sandbox Code Playgroud)
我想在用户点击按钮时在QuestionA和QuestionB组件之间切换'active'类.我怎样才能做到这一点?请记住,QuestionA和QuestionB在其render()方法中设置了自己的classNames.例如QuestionB的render():
render: function() {
return (
<section className="question-b-container">
...
</section>
);
}
Run Code Online (Sandbox Code Playgroud) 我有一项任务是将部分数据写入单独的文件:
fs.writeFile('content/a.json', JSON.stringify(content.a, null, 4), function(err) {
if(err) {
console.log(err);
} else {
console.log('a.json was updated.');
}
});
fs.writeFile('content/b.json', JSON.stringify(content.b, null, 4), function(err) {
if(err) {
console.log(err);
} else {
console.log('b.json was updated.');
}
});
fs.writeFile('content/c.json', JSON.stringify(content.c, null, 4), function(err) {
if(err) {
console.log(err);
} else {
console.log('c.json was updated.');
}
});
fs.writeFile('content/d.json', JSON.stringify(content.d, null, 4), function(err) {
if(err) {
console.log(err);
} else {
console.log('d.json was updated.');
}
});
Run Code Online (Sandbox Code Playgroud)
但现在我有4个不同的回调,所以当完成所有4个任务时,我无法得到这个时刻.是否可以并行4个writeFile调用并且只获得1个回调,这将在创建4个文件时调用?
PS
当然,我可以这样做:
fs.writeFile('a.json', data, function(err) {
fs.writeFile('b.json', data, function(err) { …Run Code Online (Sandbox Code Playgroud)