访问包含对象的数组

时间:2016-04-03 09:20:57

标签: javascript arrays object reactjs

我尝试从道具

访问数据

this.props.teachers一样,它在控制台上检索我Object {},当我尝试this.props.teachers[0]时,返回undefined,this.props.teachers[0].age检索错误,因为无法访问undefined?

我做错了什么?

enter image description here

这是代码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;

0 个答案:

没有答案