【发布时间】:2023-03-25 03:29:01
【问题描述】:
我正在尝试使用子组件呈现一个列表,但它最终没有呈现任何东西。
PropertyBar 组件中的片段:
updateSelectedCell() {
if (graph.selectedCell != null) {
this.setState({
selectedCell: graph.selectedCell,
cellProperties: Array.from(graph.selectedCell.value.attributes)
});
}
}
renderPropertyList() {
this.state.cellProperties.map(key => {
<PropertyBarItem name={key.nodeName} value={key.nodeValue} />
})
}
render() {
if (this.state.selectedCell != null) {
return (
<div>
<Button variant="contained" color="primary" fullWidth={true} onClick={() => this.updateSelectedCell()}> View properties </Button>
<List>
{this.renderPropertyList}
</List>
</div>
)
}
return (
<div>
<Button variant="contained" color="primary" fullWidth={true} onClick={() => this.updateSelectedCell()}> View properties </Button>
<List>
<p>Click on a cell to view its properties.</p>
</List>
</div>
)
}
当用户点击按钮时,它会使用一个数组更新状态,然后应该使用数组内的键呈现一个 PropertyBarItem 列表。它最终不显示任何内容,但不会崩溃。使用简单的 p 标签进行测试,它也不会呈现任何内容:
renderPropertyList() {
this.state.cellProperties.map(key => {
<p> {key} </p>
})
}
【问题讨论】:
标签: reactjs