【发布时间】:2014-10-05 15:51:27
【问题描述】:
我正在尝试获得点击,甚至可以使用reactjs 中的表格。我的第一次尝试是使整行可点击。这是我的代码:
var UserList = React.createClass({
getInitialState: function() {
return getUsers();
},
handleClick: function(e) {
console.log("clicked");
},
render: function() {
var users = this.state.users.map(function(user) {
return (
<tr onClick={this.handleClick}>
<td>{user.name}</td>
<td>{user.age}</td>
<td></td>
</tr>
);
});
return(
<div className="container">
<table className="table table-striped">
<thead>
<tr>
<th>Name</th>
<th>Age</th>
<th>Full Detail</th>
</tr>
</thead>
<tbody>
{users}
</tbody>
</table>
</div>
);
}
});
这不起作用。然后我尝试在表格中添加一个按钮:
<button className="btn" onClick={this.handleClick}>Full Detail</button>
那也没用。我在整个应用程序中都有其他 onClick 工作,但是如何使用表格来完成这项工作?
【问题讨论】:
标签: reactjs