首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >将枚举中的{{}}替换为react中api中的数据

将枚举中的{{}}替换为react中api中的数据
EN

Stack Overflow用户
提问于 2019-03-10 14:35:20
回答 1查看 45关注 0票数 0

有没有办法将枚举(share.tsx)中的{{session_id}}和{{skill_name}}替换为api中的数据。下面是我的尝试:

代码语言:javascript
复制
Shared.tsx    

----------
export enum NotificationMessage{
    ASSIGNED_ALERT ="session {{session_id}} is now assigned to you.",
    OFFERED_ALERT ="You have received session {{session_id}} on skill \"{{skill_name}}\"",
    ASSIGN_CONFIRM_MESSAGE= "You have received session {{session_id}} on skill \"{{skill_name}}\"",

}

File B.tsx
-----------

import {NotificationMessage} from "../../shared";

// data from api
switch (data){
    case A : 
      // Is there a way to replace {{session_id}}, and/or {{skill_name}} in enum (share.tsx) with data from api.
      //My attempt to replace {{session_id}} with data.session_id
      stringA = 'NotificationMessage.ASSIGNED_ALERT%s', data.session_id;
    case B : 
      //My attempt to replace {{session_id}} and {{skill_name}} with data.session_id and data.skill_name
      stringB = NotificationMessage.OFFERED_ALERT, data.session_id, data.skill_name;
    case C : 
      //My attempt to replace {{session_id}} and {{skill_name}} with data.session_id and data.skill_name
      stringC = NotificationMessage.ASSIGN_CONFIRM_MESSAGE, data.session_id, data.skill_name;
 }
EN

回答 1

Stack Overflow用户

发布于 2019-03-10 15:17:38

请在此处查看可能的解决方案https://stackoverflow.com/a/4256130/7141073

您应该稍微更改regexp,因为您的字符串稍有不同。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/55085111

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档