1 回答
TA贡献1828条经验 获得超3个赞
我想这是因为你这样做:
var btn = document.getElementById("myBtn");大概你只有1个ID被调用,或者如果你确实有更多,那么它只会调用它每次找到的第一个IDmyBtn
你应该改变方法。将所有用户存储在具有唯一 ID 的对象数组中。 在此数组上显示所有用户。然后,当您单击一个时,将 作为参数传入。然后使用它来过滤数组以显示相关内容。下面是简化的示例.mapIDid
const users = [
{id: 1, name: 'Tom', email: 'tom@test.com},
{id: 2, name: 'Sam', email: 'sametest.com},
]
然后映射它们以呈现它们
users.map((user) =>
<div onClick={() => renderModalForCorrectUser(user.id)>
<div> {user.name} </div>
<div> {user.email} </div>
</div>
然后
function renderModalForCorrectUser(id) {
//find the correct user by id
// then do the opening of the modal by passing in the relevant users details
}
添加回答
举报
