渲染期间为什么出现错误?

时间:2017-12-28 11:01:02

标签: javascript reactjs highcharts react-highcharts

我在我的项目中使用react-highcharts。我想动态生成图表组件并根据用户的选择更改其编号。我编写了组件和函数,它获取数据并生成highcharts组件数组并返回它们:

$

在渲染过程中我犯了错误:

export default class ContentChartItem extends Component {

    constructor(props) {
        super(props);
        this.state = {
        }

        this.config = {}

    render() {
        let { process_data } = this.props;
        let config = this.config;

        return (
            <div className="column">
                {typeof process_data == "undefined" ? " "
                    :
                    <div className="ui segment">
                        {this.getChartItemsList}
                        <div className="ui button tiny fluid sidenav4">
                            Info
                        </div>
                    </div>
                }
            </div>
        )
    }

    getChartItemsList = () => {
        let config = this.config;
        let { process_data } = this.props;
        let chartContainers = [];
        for ( let i=0; i<process_data.length; i++ ) {
            chartContainers.push( <ReactHighcharts config = {config}> </ReactHighcharts> )
        }

        return chartContainers;
    };


}

可能是什么原因?我该如何解决呢。

1 个答案:

答案 0 :(得分:1)

您忘了拨打this.getChartItemsList()

{typeof process_data == "undefined" ? " "
                    :
                    <div className="ui segment">
                        {this.getChartItemsList()}
                        <div className="ui button tiny fluid sidenav4">
                            Info
                        </div>
                    </div>
                }

顺便说一句,您可以使用以下语法执行此操作:

{
  process_data && (
  <div className="ui segment">
    {this.getChartItemsList()}
    <div className="ui button tiny fluid sidenav4">
      Info
    </div>
  </div>
)}