4列の動的テーブルがあります。4番目の列を動的なドロップダウンリストにして、ユーザーが値を変更できるようにします。
動的テーブルを作成するために、以下のチュートリアルに従いました。
https://blog.logrocket.com/complete-guide-building-smart-data-table-react/
私はReactの初心者です。
これが私がテーブルを必要とする方法です。内容がぼやけてすみません。
この例を見てください:
Table.Js
import React, { Component } from 'react'
class Table extends Component {
constructor(props) {
super(props)
this.state = {
students: [
{ id: 1, name: 'Wasif', age: 21, email: '[email protected]' },
{ id: 2, name: 'Ali', age: 19, email: '[email protected]' },
{ id: 3, name: 'Saad', age: 16, email: '[email protected]' },
{ id: 4, name: 'Asad', age: 25, email: '[email protected]' }
]
}
}
viewRow(id,e) {
alert('selectedId:'+ id);
localStorage.setItem('transactionId',id);
}
renderTableData() {
return this.state.students.map((student, index) => {
const { id, name, age, email } = student //destructuring
return (
<tr key={id}>
<td>{id}</td>
<td>{name}</td>
<td>{age}</td>
<td>{email}</td>
<td>
<select name="cars" id="cars">
<option value="volvo">Volvo</option>
<option value="saab">Saab</option>
<option value="mercedes">Mercedes</option>
<option value="audi">Audi</option>
</select>
</td>
<td><button onClick={(e) => this.viewRow(id, e)}>View Row Id</button></td>
</tr>
)
})
}
結果:
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加