【发布时间】:2017-07-16 13:37:09
【问题描述】:
我有一个呈现标签的组件。它遍历地图并显示数据。我尝试使用 forEach 但它不起作用。但是,如果我将地图转换为数组,它会起作用(foreach 也不适用于数组)。我在这里错过了什么?
这行得通:
render(){
return(
<div class="container">
{Array.from(this.props.tags.values()).map((tag,i) => (
<Tag
handleKeyDown={this.handleKeyDown.bind(this)}
handleBlur={this.handleBlur.bind(this)}
handleTouchTap={this.handleTouchTap.bind(this)}
handleRequestDelete={this.handleRequestDelete.bind(this)}
tag={tag}
key={i}
/>
))}
</div>
)
}
这不是:
render(){
return(
<div class="container">
{this.props.tags.forEach((tag,i) => (
<Tag
handleKeyDown={this.handleKeyDown.bind(this)}
handleBlur={this.handleBlur.bind(this)}
handleTouchTap={this.handleTouchTap.bind(this)}
handleRequestDelete={this.handleRequestDelete.bind(this)}
tag={tag}
key={i}
/>
))}
</div>
)
}
【问题讨论】:
标签: javascript reactjs dictionary foreach