0
如何使表格行可点击来编辑和更新详细信息?我从pouchdb中检索这些细节。反应使表格可点击并编辑详细信息
我对你们的评价粘贴下面我的代码部分:
this.state = {docs: []}
this.db = this.props.db
componentDidMount() {
this.updateDocs()
this.db.changes({
since: 'now',
live: true
}).on('change', (change) => {
this.updateDocs()
}).on('error', (err) => {
console.error(err)
})
}
updateDocs() {
this.db.allDocs({include_docs: true}).then((res) => {
var docs = res.rows.map((row) => row.doc)
this.setState({docs})
})
}
和下表:
<div className='table-list'>
<table>
<thead>
<tr>
<th>Registration Type</th>
<th>First Name</th>
<th>Middle Name</th>
</tr>
</thead>
<tbody>
{this.state.docs.map((doc) => <DataRow key={doc._id} doc={doc} {...this.props} />)}
</tbody>
</table>
</div>
class DataRow extends React.Component {
render() {
let {doc} = this.props
return (
<tr>
<td>{doc.RegistrationInfo['registrationtype']}</td>
<td>{doc.RegistrationInfo['firstname']}</td>
<td>{doc.RegistrationInfo['middlename']}</td>
</tr>
)
}
}
我希望能够点击并编辑每一行。
您如何计划在编辑后保存每行的更改?无论如何,一种解决方案可能是在'DataRow'的'tr'上添加一个'onClick',然后使用[HTMLElement.contentEditable'](https:// developer)设置其子元素('td'元素)。 mozilla.org/en/docs/Web/API/HTMLElement/contentEditable) – glhrmv