【发布时间】:2018-01-23 00:55:55
【问题描述】:
我正在使用 .map 在 React 应用中创建一个小列表
{
this.state.rooms.map((anything, indexPos) =>
<p className='rooms'
onClick={this.test}
key={indexPos}>{anything.name}
</p>
)
}
onClick方法调用的'test'函数如下:
test = (e) => {
alert();
}
我的问题是我应该在 alert 方法的“()”中输入什么代码来提醒点击了哪个特定房间?
了解我的构造函数的样子也可能会有所帮助:
constructor(props) {
super(props);
this.state = {
rooms: [],
display: 'none',
newRoomName: 'New room',
currentRoom: ''
};
this.roomsRef = this.props.firebase.database().ref('rooms');
}
这是与 Question 关联的 git 文件的 LINK。
能够提醒();然后,我单击的任何房间的“键”属性或索引或房间名称都将允许我“渲染”选定的房间。感谢您的任何建议。
【问题讨论】:
-
e.target.key 可能
-
不,这给出了“未定义”的 Jaromanda。谢谢
标签: javascript reactjs getattribute