我找不到在包含数组的对象字段中动态输入值的方法
这是对象。我如何通过在react中动态在listItem键中输入fyage falue
{
name: "",
dueDate: "",
grossAmount: "",
billNo: "",
billDate: "" ,
listItem:[{ productName: "", quantity: null, price: null, amount: null, gstRate: null}],
gstAmount: null,
netAmount: null,
notes: "",
status: " "
}
this is the object . How can i input value through form tag in listItem key dynamically in react
{
name: "",
dueDate: "",
grossAmount: "",
billNo: "",
billDate: "" ,
listItem:[{ productName: "", quantity: null, price: null, amount: null, gstRate: null}],
gstAmount: null,
netAmount: null,
notes: "",
status: " "
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
假设对象使用您可以执行的USESTATE挂钩存储在状态中
。。
状态输入:
对于输入,您可以执行这样的操作。注意:我只是为了更改productName而这样做,但是您可以为OBJ的任何其他键执行此操作。
Assuming object is stored in a state using useState hook
You can do..
state for input:
And for input you can do something like this. Note: I just did this for changing productName, but you can do this for any of the other keys of the obj.
首先将
名称
属性属于您的输入元素。然后创建一个onChangeHandler函数。此功能可以处理您拥有的每个输入的所有更改。您的输入(名称属性应与您的对象密钥相同):
onChangeHandler函数:
First add
name
attribute to your input element. Then create a onChangeHandler function. This function can handle all changes for every inputs you have.Your inputs (the name attribute should be the same as your object key):
onChangeHandler function: