0

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

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

1 回答 1

0

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

您应该稍微更改一下正则表达式,因为您的字符串略有不同。

于 2019-03-10T07:17:38.297 回答