在循环下反应不渲染 <th>

React not rendering <th> under loop

标签下的名称和产品得到渲染,但循环没有被渲染..但我可以看到 console.nad 中的值没有抛出任何错误...请麻

<tr>
   <th>name</th>
   <th>productID</th>
     {this.state.product[0].customCoulmns.forEach(function (columnhead) {
     console.log("columnhead lolzz ",columnhead.columnName);
     return <th key={columnhead.columnName}>{columnhead.columnName}</th>
        }.bind(this))
  }
     </tr>

forEach doesn't return anything to the caller. You should be using a map 改为:

this.state.product[0].customCoulmns.map(function (columnHead) {
    return <th key={columnHead.columnName}>{columnHead.columnName}</th>
})

注意这里不需要绑定this。只有当您需要引用 this 时才需要这样做,并且调用函数时原始值将不再在范围内。在这种情况下,这些条件都不成立。

此外,作为一般性建议,请注意代码中拼写和大小写的一致性 :)