async onSubmitConditionDuration() {
var param = (this.state.health_condition+"_personal_age")
try {
axios.patch(URL,
{
param: this.state.condition_duration, //param is a variable that represents a field name at the endpoint(URL)
})
.then((response)=>{
console.log(response.status);
})
.catch((errors) => {
console.log(errors);
})
}
catch(errors){
console.log(errors);
}
}
我试图在请求的json正文中将字段名称作为变量,以便可以根据变量的值动态更新字段。通过使用以上语法,补丁请求无法更新“ param”中存储的值所表示的字段。
如何用Javascript完成?
我正在使用React Native应用程序
您可以使用以下[]
语法:
var param = (this.state.health_condition+"_personal_age")
var object = {
[param]: this.state.condition_duration,
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句