javascript - ReactJS:预期的属性速记对象速记
问题描述
我有一个提交的表格。单击它时,我创建一个对象以将这些数据发送到 POST。
所以我有 saveEntity 常量:
const saveEntity = (event, errors, values) => {
// this is the const that is signed as error:
const valoreComune: any = comCod ? { comCod: { comCod: comCod } } : personEntity.comCod ? { comCod: { comCod: personEntity.comCod.comCod } } : { comCod: null };
//....
const entity = { // this is the object that I pass to post
// ....
valoreComune
}
}
我需要重新创建这个对象结构:
comCod: {
comCod: value
}
或者
comCod: null
现在我收到此错误:
预期的属性速记对象-速记
现在我通常以这种方式直接解决写作:
const entity = {
valoreComune
}
但它不起作用。我能怎么做?
解决方案
您应该为此部分使用对象简写语法:
{ comCod: { comCod: comCod } }
是这样写的:
{ comCod: { comCod } }
推荐阅读
- excel - 有没有办法在 Excel 64 位的用户窗体上使用 DatePicker 而无需下载第三方插件?
- excel - Access Excel VBA在列下查找具有相同值的单元格
- mongodb - MongoDB Go 驱动程序重置连接
- api - 通过 API 恢复预约状态
- regex - 使用ansible在文件中查找带有$的单词
- graphql - 无法使用 graphql_base 模块从邮递员那里获取记录
- angular - 尝试到达外部 api 时 Angular 代理超时
- powershell - 在正在运行的 powershell 脚本中添加菜单选项
- angularjs - angularjs 将复选框值从整数更改为布尔值
- javascript - Javascript:查找数组中对某个键具有特定值的所有元素