Javascript 反应使用表中的数据,从输入字段中获取数据,并在单击按钮后使用数据将请求发送到数据库
非常新的反应,我目前有一个表如下所示。我有两列是从数据库中提取的数据,一个输入字段列和旁边的按钮。本质上,它是用于库存管理的。您将看到数据库中的数量,如果要重新进货或使用库存,您将在数量输入字段中添加数量,然后按restock或use,它将向数据库发送请求以执行相应操作。这可能不是制作这样一个表的最佳方法,因为我从几篇不同的文章和教程中提取了代码。任何关于如何前进并让我的重新进货/使用按钮使用输入字段数据和数量的建议都会很好 下面是我当前在渲染函数中的内容Javascript 反应使用表中的数据,从输入字段中获取数据,并在单击按钮后使用数据将请求发送到数据库,javascript,reactjs,Javascript,Reactjs,非常新的反应,我目前有一个表如下所示。我有两列是从数据库中提取的数据,一个输入字段列和旁边的按钮。本质上,它是用于库存管理的。您将看到数据库中的数量,如果要重新进货或使用库存,您将在数量输入字段中添加数量,然后按restock或use,它将向数据库发送请求以执行相应操作。这可能不是制作这样一个表的最佳方法,因为我从几篇不同的文章和教程中提取了代码。任何关于如何前进并让我的重新进货/使用按钮使用输入字段数据和数量的建议都会很好 下面是我当前在渲染函数中的内容 render() {
render() {
return (
<div>
<h3>Restock/Use</h3>
<table className="table table-striped table-bordered table-hover" style={{marginTop:20}}>
<thead>
<tr>
<th>Description</th>
<th>Current Quantity</th>
<th>Amount</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
{this.inventoryList(this.state.inventory)}
</tbody>
</table>
</div>
)
}
那么,具体的问题是什么?你能提供一个错误日志吗?当它不工作时会产生错误日志吗?工具栏中的两个按钮都有相同的id。。。。不是问题的原因-但evert id必须是唯一的。-此外,您的restockInventory需要向它传递一个索引参数,但onClick没有。@TheGrandJ没有错误。我只是试着去做我前面描述的事情,我正在寻求帮助。我不知道如何继续前进。
inventoryList = (inventory) =>{
return inventory.map((inventory, index) => (
<tr>
<td>{index}</td>
<td>{inventory.description}</td>
<td>{inventory.quantity}</td>
<input type='number'></input>
<td>
<div class="btn-toolbar">
<button type="button" id='btnRestock' class="btn-primary btn-sm" onClick={this.restockInventory}>Restock</button>
<button type="button" id='btnRestock' class="btn-danger btn-sm">Use</button>
</div>
</td>
</tr>
))
}
restockInventory(index){
console.log('HELLLOO')
console.log(this.state.inventory)
}