【问题标题】:how to add <a> HTML tag or URL in object array in .ejs如何在 .ejs 的对象数组中添加 <a> HTML 标记或 URL
【发布时间】:2021-12-14 11:20:10
【问题描述】:

我是创建数组对象的新手,我不知道如何在数组中的&lt;a&gt; 标签中添加链接

目标代码:

powerUpList: [ 
  {
      id:1,
      name:'Stack Export',
      description:'Export your complete stack back in an excel sheet. ',
      url: "https://help.stackby.com/article/145-export-stack-in-excel",
      category:'Data Recovery',
      status:0,
    },
    {
      id:2,
      name:'Microsoft Excel Importer',
      description:'Import an excel file to create a new stack or import it to a table. ',
      url: "https://help.stackby.com/article/146-excel-importer",
      category:'Import',
      status:0,
    },
    {
      id:3,
      name:'Append CSV file in an existing table',
      description:'Import a CSV file into an existing table and map the columns to take the form of your table. ',
      url: "https://help.stackby.com/article/144-import-data-in-an-existing-table",
      category:'Data Transformation',
      status:0,
    },
],

powerUpCategoryList: [
  'Data Recovery',
  'Import',
  'Data Transformation',
  'Sharing',
  'Automation',
  'Apps',
],

这是我的 JS 对象代码

这是 .ejs 中的实际代码,所有实例都在其中执行,并且手风琴不会关闭,

powerup.ejs

<div class="col-md-9" id="root">
  <div role="tablist" id="accordion-1">
    <%for (var i = 0; i < powerUpList.length; i++) { %>
      <div class="card">
        <div class="card-header" role="tab">
          <a data-toggle="collapse" aria-expanded="true" aria-controls="accordion-1 .item-<%= i+1 %>" href="div#accordion-1 .item-<%= i+1 %>"><%= powerUpList[i].name%></a>

          <%if (powerUpList[i].status == 0) { %>
              <a class="live-lable status-live" >
                Live 
              </a>
            <%}else if(powerUpList[i].status == 1){-%>
              <a class="live-lable status-comingsoon" >
                Coming soon 
              </a> 
            <%}else if(powerUpList[i].status == 2){-%>
              <a class="live-lable status-beta" >
                In-Beta 
              </a> 
            <%}-%>
        </div>
        <div class="collapse show item-<%= i+1 %>" role="tabpanel" data-parent="#accordion-1">
            <div class="card-body">
                <p class="card-text" ><%= powerUpList[i].description%></p>
               --------- HERE I WAnt to show **URL** as learn more
              <a href="<%- powerUpList[i].url%>" target="_blank">Learn more..</a> 
            </div>
        </div>
      </div>
    <%}-%>
  </div>
</div>

这里,我想在 url: "https://help.stackby.com/article/145-export-stack-in-excel", 中显示为下载链接,然后打开新窗口,但我不知道如何在文件中添加&lt;a&gt;标签

【问题讨论】:

  • 很不清楚你想要什么。您通常不会将 HTML 存储在对象中。当您编码 &lt;a href="&lt;%- powerUpList[i].url%&gt;" 时,什么对您不起作用?
  • @mplungjan 我想在 中显示 url 对象了解更多

标签: javascript html ejs


【解决方案1】:

据我了解,你可以做

<a href="<%- powerUpList[i].url %>">learn more</a>

【讨论】:

    猜你喜欢
    • 2021-12-01
    • 2021-07-31
    • 1970-01-01
    • 2022-10-22
    • 1970-01-01
    • 2021-04-06
    • 2018-02-22
    • 2016-03-17
    • 1970-01-01
    相关资源
    最近更新 更多