Javascript 为什么渲染时会出现错误?
我正在我的项目中使用。我想生成图表组件dynamicali,并根据用户的选择更改它们的编号。我编写了组件和函数,用于获取数据并生成highcharts组件数组并返回它们:Javascript 为什么渲染时会出现错误?,javascript,reactjs,highcharts,react-highcharts,Javascript,Reactjs,Highcharts,React Highcharts,我正在我的项目中使用。我想生成图表组件dynamicali,并根据用户的选择更改它们的编号。我编写了组件和函数,用于获取数据并生成highcharts组件数组并返回它们: export default class ContentChartItem extends Component { constructor(props) { super(props); this.state = { } this.config = {}
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;
};
}
导出默认类ContentChartItem扩展组件{
建造师(道具){
超级(道具);
此.state={
}
this.config={}
render(){
让{process_data}=this.props;
让config=this.config;
返回(
{进程类型_数据==“未定义”?“”
:
{this.getChartItemsList}
信息
}
)
}
getChartItemsList=()=>{
让config=this.config;
让{process_data}=this.props;
设chartContainers=[];
对于(设i=0;i您忘记调用this.getChartItemsList()
:
{typeof process_data==“未定义”?“
:
{this.getChartItemsList()}
信息
}
顺便说一下,您可以使用以下语法执行条件:
{
process_data && (
<div className="ui segment">
{this.getChartItemsList()}
<div className="ui button tiny fluid sidenav4">
Info
</div>
</div>
)}
{
处理数据&&(
{this.getChartItemsList()}
信息
)}
因为您忘记了()
这里:{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>
)}