0
對於reactjs和JavaScript,所有東西都還是新手,所以這可能很簡單,但我還沒有找到一個在線搜索的例子。如何使用onClick在同一行中獲取輸入數據 - reactjs
我想建立一個表,每一行都有一個輸入框和一個onClick /提交,然後發送該函數中該行輸入的輸入量,或者以某種方式訪問該行的輸入數據。行是從保存狀態的數組構建的。
這裏是我目前所處位置的精簡代碼。這只是被更高級別的容器調用的表,它會傳遞biweeklyPays和saveChanges。
function PayoutsTable(props) {
var payoutRows = []
var biweeklyPays = props.biweeklyPays
for (let b of biweeklyPays) {
payoutRows.push(
<tr>
<td>{b.user.first_name + ' ' + b.user.last_name}</td>
<td>{b.biweeklyPay.payoutAmount}</td>
<td><input className="form-control" type="number" id="payoutAmount" step=".01" min="0" /></td>
<td><button className="btn btn-primary" onClick={() => props.saveChanges(b)}>Submit</button></td>
</tr>
)
}
return (
<div>
<table className="table table-responsive table-striped">
<thead>
<tr>
<th>Name</th>
<th>Payout Amount</th>
<th></th>
<th></th>
</tr>
</thead>
<tbody>
{payoutRows}
</tbody>
</table>
</div>
)
}