我尝试从道具
访问数据与this.props.teachers
一样,它在控制台上检索我Object {}
,当我尝试this.props.teachers[0]
时,返回undefined,this.props.teachers[0].age
检索错误,因为无法访问undefined?
我做错了什么?
这是代码snipet
var React = require('react');
var Router = require('react-router');
var helpers = require('../utils/helpers');
var ResultList = React.createClass({
getInitialState: function(){
return{
usersDataArr:{},
}
},
componentWillMount : function() {
helpers.getAvaiabilityResults(this.props.params.places,this.props.params.branch,this.props.params.dayOfMonth,this.props.params.timeStart,this.props.params.timeEnd)
.then(function(data){
this.setState({
usersDataArr:data.AvaiabilityResults
})
}.bind(this))
},
render: function(){
return(
<div>
ResultList
<Results teachers={this.state.usersDataArr[0]} />
</div>
);
}
});
var Results = React.createClass({
componentDidMount: function() {
console.log(this.props.teachers);
},
render: function() {
return (
<h1>Results</h1>
);
}
});
module.exports = ResultList;