componentDidMount不被触发

嗨Im新的React和nodeJS,我试图通过反应调用我的nodejs api,并且我的componentDidMount甚至在渲染页面后都不会被触发。 有人可以给我一些想法,我可能会错过的地方。

var React = require('react'); module.exports = React.createClass({ getInitialState: function() { return { jobs: [] } }, componentDidMount: function() { console.log("mount"); var _this = this; this.serverRequest = $.ajax({ .... }.bind(this) }); }, componentWillUnmount: function() { this.serverRequest.abort(); }, render: function() { return ( <div><h1>Jobs</h1> {this.state.jobs.map(function(job) { return ( <div key={job.id} className="job"> {job.name} {job.address} </div> ); })} </div> ) } }); 

在我的NodeServer.js文件中,我以这种方式调用,只有工作正在显示在我的HTML页面

 app.get('/', function(request, response) { var htmlCode = ReactDOMServer.renderToString(React.createElement(Component)); response.send(htmlCode); }) 

在后台渲染时,不能使用React组件生命周期方法加载数据,这只能在客户端中使用。 在服务器上渲染组件时,只渲染一次,不提供数据。 数据是asynchronous加载的,当它完成时,你的组件已经被渲染。 您必须在组件外部获取数据,然后将其作为道具传递给组件。