1
正如我在console.log中看到的那樣正確地聲明瞭狀態,但是我的Jumbotron組件根本沒有使用它。另外,它的效果很好,但{this.state.name}沒有顯示出來。React組件根本沒有使用{this.state.something}
var React = require('react');
var TeamStore = require('../stores/TeamStore');
import Jumbotron from 'react-bootstrap/lib/Jumbotron';
function getTeamState() {
return { name: TeamStore.getSelected() };
}
console.log(TeamStore.getSelected());
var TeamApp = React.createClass({
getInitialState: function() {
return {getTeamState };
},
componentDidMount: function() {
TeamStore.addChangeListener(this._onChange);
},
componentWillUnmount: function() {
TeamStore.addChangeListener(this._onChange);
},
render: function() {
return (
<Jumbotron>
<h1 style={{"marginLeft": "270px"}}>{this.state.name}</h1>
</Jumbotron>
)
},
_onChange: function() {
this.setState(getTeamState());
}
});
module.exports = TeamApp;
我想,最初,但我一直收到此錯誤:'TeamApp.getInitialState():必須返回一個對象或null' – Username
沒關係,我收回這句話。當我最初嘗試時,我忘記了括號 – Username