在另一种反应方法中调用方法

时间:2017-06-27 22:59:21

标签: javascript reactjs

我正在学习反应,而且我遇到了问题。

关键是,我正在开发一个从JSON文件中提取个人信息的组件。然后,我做了一个方法来获取我的地址,我需要把它放在我的个人方法中,如下所示:

import React, { Component } from 'react';
import Me from './me.json';

class Basic extends Component {
    personal() {
        const person = Me.personal.map(function(me, index) {
            return (
                <div className="Curriculum-header" key={index.toString()}>
                    <div className="content-left">
                        <h1 className="name">{me.name}</h1>
                        <h2>Developer</h2>
                        <h3 className="age">{me.age} anos</h3>
                    </div>
                    <div className="content-middle">
                        {this.address()} //here's the error... This method's call isn't working
                    </div>
                    <div className="content-right">
                        <img src={me.pic} alt={me.name} />
                    </div>
                </div>
            );
        });
        return ( person );
    }
    address() {
        const enderecos = Me.personal[0].address.map(function(endereco, index) {
            return (
                <div className="Address-info" key={endereco.toString()}>
                    <p>{endereco.street + ', ' + endereco.houseNr + ', ' + endereco.complement}</p>
                    <div id="map" data-lat={endereco.lat} data-long={endereco.long}></div>
                </div>
            );
        });
        return ( enderecos );
    }
    constructor(props) {
        super(props);
        this.state = {};

        this.personal = this.personal.bind(this);
        this.address = this.address.bind(this);
    }
    render() {
        return (
            <div className="Personal-info">
                <h2 className="Curriculum-title">Sobre</h2>
                {this.personal()}
            </div>
        )
    }
}

export default Basic;

有人可以帮我这个吗?

0 个答案:

没有答案