繁体   English   中英

ReactJS:预期属性速记对象速记

[英]ReactJS: Expected property shorthand object-shorthand

我有一个提交表单。 单击它时,我创建一个对象将这些数据发送到 POST。

所以我有 saveEntity const:

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 } }

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM