首页 > 解决方案 > 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
    }

但它不起作用。我能怎么做?

标签: javascriptreactjstypescript

解决方案


您应该为此部分使用对象简写语法:

{ comCod: { comCod: comCod } }

是这样写的:

{ comCod: { comCod } }

推荐阅读