【发布时间】:2020-09-01 17:34:50
【问题描述】:
我正在映射一个数组以获取每个按钮的文本。我想为每个按钮映射一个数组以显示映射数组的文本。
所以按钮标题的数组是:
const arr1 = ["one", "two", "three"]
点击每个按钮时显示的文本是:
const arr2 = ["button one", "button two", "button three"]
所以我希望带有文本“one”的按钮在单击时将文本“button one”显示为 p 标签。
这是我目前所拥有的
const myComp = () => {
const arr1 = ['one', 'two', 'three']
const arr2 = ['button one', 'button two', 'button three']
const mapping = () => {
arr2.map((arr) => {
return <p>{arr}</p>
})
}
return (
<>
{arr1.map((data) =>
<button onClick={mapping()}>
{data}
</button>
)}
</>
)
【问题讨论】:
标签: javascript arrays reactjs mapping