gpt4 book ai didi

javascript - 如何在循环中生成react html

转载 作者:行者123 更新时间:2023-11-29 18:58:04 24 4
gpt4 key购买 nike

<分区>

好吧,这在过去的几个小时里一直让我抓狂。我非常想拥有一个函数,该函数根据作为参数传递给它的数组中的对象生成 html。我的代码看起来像这样:

handleEvents = (array) => {
if(array.length > 0){
array.forEach(function(each){
return(<h1>hello {each.name}</h1>)
})
}

在我的渲染组件中我有这个:

<div className="caption left-align">
<h3>Upcoming events</h3>
{this.handleEvents([{name: "Dave"}, {name: "Mary"}, {name: "Chris"}])}
</div>

但是当我运行这段代码时,屏幕上没有任何输出。我该怎么办?

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com