Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript React动态表格标题未显示_Javascript_Reactjs - Fatal编程技术网

Javascript React动态表格标题未显示

Javascript React动态表格标题未显示,javascript,reactjs,Javascript,Reactjs,我有一个react组件来呈现一个表。我工作得很好,只是我将标题更改为动态呈现,而不是硬编码标题。现在动态标题行没有显示,即使我可以在console.log中看到我的数据存在。这种事我已经做了一千次了。我是不是忽略了什么 <table> <thead> <tr> <th colSpan='10'><label>Weekly Summary: {this.props.select

我有一个react组件来呈现一个表。我工作得很好,只是我将标题更改为动态呈现,而不是硬编码标题。现在动态标题行没有显示,即使我可以在console.log中看到我的数据存在。这种事我已经做了一千次了。我是不是忽略了什么

<table>
        <thead>
          <tr>
            <th colSpan='10'><label>Weekly Summary:  {this.props.selectedYear}</label></th>
          </tr>
          <tr>
            <th>Category</th>

            {/* <th>Header 5</th>
            <th>Header 6</th>
            <th>Header 7</th>
            <th>Header 8</th>
            <th>Header 9</th> */}

            {console.log(this.props.transactions)}
            {
              this.props.transactions.map(function(el,i) {
                console.log(el.category)
                if (el.category == "Total"){
                  Object.keys(el.periods).map(function(key,index) {
                    console.log("week value: ", key)
                    return <th key={key}>{key}</th>
                  })
                }  
              })
            }
            <th>Total</th>
          </tr>
        </thead>
        <tbody>
        </tbody>
</table>
您在this.props.transactions上的映射函数现在返回未定义,这就是为什么没有渲染这些属性。你需要从

Object.keys(el.periods).map(function(key,index) {


通过这种方式,您可以返回调用Object.keys上的map的结果。

!谢谢你把它修好了!
Object.keys(el.periods).map(function(key,index) {
return Object.keys(el.periods).map(function(key,index) {