【发布时间】:2025-12-26 03:05:06
【问题描述】:
我有一个类似的构造函数
constructor() {
this.state = {
item_details : {}
}
}
someFunc(next_item_key,next_item_value) {
//append this next_item_key , next_item_value pair to item_detials
}
我需要将 someFunc 中的 next_item 添加到我的状态变量 item_details..
示例: 我的 item_details 看起来像这样
item_details : {'abc' : 'xyz' , 'a12' : '123' }
我的 next_item 会是这样的
next_item_key = 'qwerty'
next_item_value = 'pqrs'
我的结果 item_details 应该看起来像
item_details : {'abc' : 'xyz' , 'a12' : '123' , 'qwerty' : 'pqrs' }
我应该在 someFunc 中写什么来得到这个结果
【问题讨论】:
标签: javascript reactjs object react-native setstate