根据用户选择在字符串中更改/替换值

问题描述 投票:0回答:2

我正在研究一个录取通知书模板,该模板将根据从候选人列表中选择的候选人来替换/修改名称,地址,角色,薪水等动态数据点。动态数据点有固定的语法,即它们将包含在<<>>中,例如:

Welcome to the family, <<Name>> 
You will be paid <<Salary>> for the duration of your employment. 

换句话说,这几个数据点将通过选择我们要提供的职位的候选人而改变,其余模板将保持不变。这是一个demo to help you understand

这是我使用1个模板创建的虚拟数组,在实际应用中,我可以使用不同的ClauseNames拥有许多模板,因此我正在寻找永久性的修复方法。.ts文件,模板列表:

[{

    templateId: 1,
    templateName: "Offer",
    clauses: [
      {
        clauseName: "Introduction",
        clauseId: 1,
        texts: [
          {
            text: "Hello <<Name>>, Welcome to the Machine",
            textId: 1,
          }]
      },
      {
        clauseName: "Address",
        clauseId: 2,
        texts: [
          {
            text: "<<Address>>",
            textId: 2,
          }]
      },
      {
        clauseName: "Date Of Joining",
        clauseId: 3,
        texts: [
          {
            text: "You can join us on <<DateOfJoining>>",
            textId: 3,
          }]
      },
    ]
  }]

这是候选人名单,

  candidateList = [
    { name: "Simba", address: "Some Random Cave" },
    { name: "Doe John", address: "line 4, binary avenue, Mobo" },
    { name: "B Rabbit", address: "8 mile road, Detroit" },
    { name: "Peter Griffin", address: "Spooner Street" },
    { name: "Speedy Gonzales", address: "401, hole 34, Slyvester Cat Road" },
    { name: "Morty", address: "Time Machine XYZ" },
    { name: "Brock", address: "pokeball 420, Medic center" },
  ]

我正在研究一个录取通知书模板,该模板将根据从候选人列表中选择的候选人来替换/修改名称,地址,角色,薪水等动态数据点。有固定的...

javascript html angular typescript dynamic-data
2个回答
0
投票

您可以使用正则表达式替换那些占位符,例如:


0
投票

看看this demo

© www.soinside.com 2019 - 2024. All rights reserved.