export class UsersTable extends React.Component {
constructor() {
super();
this.state = {
info: null
};
}
componentWillMount() {
fetch("http://localhost:8081/milltime/getUsers")
.then(res => res.json())
.then(info => {
this.setInfo(info);
});
}
setInfo(info) {
const state = this.state;
state['info'] = info;
this.setState(state);
}
render() {
const info = this.state.info;
if (!this.state.info) {
return null;
}
let listItems = [];
for (var i = 0; i < info['mta:getUsersResponse']['mta:users'].length; i++) {
listItems.push(
<tr>
<td>{info['mta:getUsersResponse']['mta:users'][i]['mta:UserId']}</td>
<td>{info['mta:getUsersResponse']['mta:users'][i]['mta:FullName']}</td>
<td>{info['mta:getUsersResponse']['mta:users'][i]['mta:CostHour']}</td>
</tr>);
}
return(
<div className="usersTable">
<Table striped bordered condensed responsive hover>
<thead>
<tr>
<th>Id</th>
<th>Full Name</th>
<th>Hour cost</th>
</tr>
</thead>
<tbody>
{listItems}
</tbody>
</Table>
</div>
);
}
}
이것은 사용자를 확보하고 데이터 3 열을 표시하는 테이블에 대한 코드입니다. 내가 겪고있는 문제는 테이블을 선택할 수 있다는 것입니다. 테이블을 선택하면 해당 셀의 데이터를 가져 와서 선택한 셀의 사용자 ID를 사용하여 검색 할 수 있습니다. 누구나 깔끔한 해결책을 얻었습니까? 나는 React bootstrap을 사용하고있다.반응 부트 스트랩 테이블에서 표 셀을 선택하십시오.
온 클릭을? https://reactjs.org/docs/handling-events.html –