2016-11-10 58 views
0

ChartProvider正根据配置文件生成图表列表。我正在尝试渲染MainComponent中的所有图表。获取错误 - 对象作为React子项无效

我得到错误:“对象作为React子元素无效(找到:带有键{}的对象)如果您打算渲染一组子对象,请改为使用数组,或者使用createFragment对象)来自React附加组件。“

MainComponent:

var React = require('React'); 
var Chart = require('ChartProvider'); 

var MainComponent = React.createClass({  
    render: function() { 
     return (
      <div> 
       {Chart} 
      </div> 
     ); 
    } 
});   

ChartProvider.js

var item = config.wList.map(function(widget, index) {  
     return ( 
        <ChartComponent width="500px" height="400px"   
        options={{title: widget.title}} /> 
      );   
     }); 
module.exports = item ; 

Config.js文件中包含的数据:

module.exports = { 
     wList : [ { 
      title : "Average(Kbps)", 
     }, { 
      title : "Average DL(Kbps)", 
     }, { 
      title : "DL", 
     }, 
     { 
      title : "Minutes",   
     }, { 
      title : "Cell",   
     }, { 
      title : "UL",  
     }] 
     }; 
+0

继承人的作品笔,看看你能不能用叉子瑞普你的问题。 http://codepen.io/anon/pen/rWxyyv?editors=1010 – skav

+0

@skav谢谢。现在没有错误。 – user2194838

回答

0

您从一个模块通过module.exports出口,不module.export

module.exports = item; 

在您的代码中,module.exports是一个空对象,它无法呈现并导致您看到的错误消息。


与此无关,您不要关闭您的<ChartComponent>。添加/到最终解决这个问题:

<ChartComponent width="500px" height="400px" options={{title: widget.title}} /> 
相关问题