0
我试图在material-ui
的reactjs
列表项上应用单击监听器。我已经设置如下onTouchTap
它:如何在材料ui中的列表项上设置点击监听器js
_renderTodos() {
return this.state.todos.map(event => {
return (
<ListItem
primaryText={event.text}
key={event.id}
style={{ width: "100%", textAlign: "center" }}
onTouchTap={this._handleListItemClick(event)}
/>
);
});
}
_handleListItemClick(item) {
console.log("Clicked!!");
}
render() {
return (
<MuiThemeProvider>
<div>
<AppBarTest />
<FloatingActionButton
style={styles.fab}
backgroundColor={colors.blue_color}
onTouchTap={this.handleOpen}
>
<ContentAdd />
</FloatingActionButton>
<Dialog
open={this.state.open}
onRequestClose={this.handleClose}
title={strings.dialog_create_note_title}
>
<TextField
name="notetext"
hintText="Note"
style={{ width: "48%", float: "left", height: 48 }}
defaultValue={this.state.noteVal}
onChange={this.handleChange}
onKeyPress={ev => {
if (ev.key === "Enter") {
this.handleCreateNote();
ev.preventDefault();
}
}}
/>
<div
style={{
width: "4%",
height: "1",
float: "left",
visibility: "hidden"
}}
/>
<FlatButton
label={strings.create_note}
style={{ width: "48%", height: 48, float: "left" }}
onTouchTap={this.handleCreateNote}
/>
</Dialog>
<List style={{ margin: 8 }}>
{this._renderTodos()}
</List>
</div>
</MuiThemeProvider>
);
}
}
当我点击ListItem
则不会触发_handleListItemClick
方法,而不是当我点击喜欢FlatButton
和FloatingActionButton
然后它会触发任何其他组件和打印控制台消息我在_handleListItemClick
。
任何人都可以帮助我我在做什么错?
哇它的工作:)等待接受你的答案+ 1 –