我试图弄清楚当我从中调用this.setState()时为什么react.js组件没有更新。我想尝试监听所有DOM更新作为调试方式。这可能吗?
var ChangingProgressBar = React.createClass({
getInitialState: function(){
return {'percentage': 0,
'mood':'progress-bar-info'}
},
componentWillMount: function(){
self = this;
setTimeout(function(){
self.setState({'mood', 'progress-bar-danger'});
}, 2000);
},
render: function(){
return (
<div className='progress-bar {this.state.mood}'
role='progressbar' aria-valuenow='{this.state.percentage}'
aria-valuemin='0' aria-valuemax='100'
style="{{width: this.state.percentage + '%'}}">
{this.state.percentage}%
</div>
)
})
})
答案 0 :(得分:0)
self.setState({'mood', 'progress-bar-danger'});
应该是
self.setState({'mood': 'progress-bar-danger'});