kaleidosJohna
kaleidosJohna
  • 发布:2025-01-13 19:13
  • 更新:2025-01-14 14:19
  • 阅读:89

【uts】const一个对象,其属性名为其他对象的属性值,这种写法怎么实现?

分类:uts
export const DISCOUNT_TYPE = {  
    jutuike: 1,  
}  
export const DISCOUNT_TYPE_PLATFORM = {  
    [DISCOUNT_TYPE.jutuike]: "jutuike"  
}  

19:10:09.625 ‌error: Expecting property name or receiver type‌  
19:10:09.625 at common/constants.uts:57:2  
19:10:09.625 55 |  }  
19:10:09.625 56 |  export const DISCOUNT_TYPE_PLATFORM = {  
19:10:09.625 57 |   [DISCOUNT_TYPE.getNumber(jutuike)]: "jutuike",  
19:10:09.625    |    ^  
19:10:09.625 59 |  }  
19:10:09.625 ‌error: Property getter or setter expected‌  
19:10:09.625 at common/constants.uts:57:2  
19:10:09.625 55 |  }  
19:10:09.625 56 |  export const DISCOUNT_TYPE_PLATFORM = {  
19:10:09.625 57 |   [DISCOUNT_TYPE.getNumber(jutuike)]: "jutuike",  
19:10:09.625    |    ^  
19:10:09.625 59 |  }
2025-01-13 19:13 负责人:无 分享
已邀请:
DCloud_UNI_FengXY

DCloud_UNI_FengXY

动态key请使用UTSJSONObject或Map

  • kaleidosJohna (作者)

    有具体示例不,感谢

    2025-01-14 10:08

  • DCloud_UNI_FengXY

    回复 kaleidosJohna:

    后续会支持该写法:https://issues.dcloud.net.cn/pages/issues/detail?id=6919

    临时绕过方案:

    const DISCOUNT_TYPE_PLATFORM = {}

    DISCOUNT_TYPE_PLATFORM[DISCOUNT_TYPE.jutuike!] = 'jutuike'

    2025-01-14 14:59

  • kaleidosJohna (作者)

    回复 DCloud_UNI_FengXY: 好的感谢

    2025-01-14 15:16

kaleidosJohna

kaleidosJohna (作者)

顶一下

要回复问题请先登录注册