2015-08-23 47 views
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; 

回答

2

您未調用getTeamState,您不需要大括號。它改成這樣:

getInitialState: function() { 
    return getTeamState(); 
}, 
+0

我想,最初,但我一直收到此錯誤:'TeamApp.getInitialState():必須返回一個對象或null' – Username

+0

沒關係,我收回這句話。當我最初嘗試時,我忘記了括號 – Username