【问题标题】:how to add <a> HTML tag in json array object如何在 json 数组对象中添加 <a> HTML 标签
【发布时间】:2021-12-01 20:28:01
【问题描述】:

我是创建数组对象的新手,我不知道如何在 json 文件的标签中添加链接

json 对象代码:

powerUpList: [ 
  {
    id: 8,
    name: 'Automate your API column type ',
    description: 'Set automated schedules (daily, 3 days, weekly, biweekly, monthly) on your API column type and keep yourself up to date at all times. Note: Please check total limits based on your plan. ',
    category: 'Automation',
    status: 0,
  },
  {
    id: 9,
    name: 'Google Drive Sync ',
    description: 'Sync your stacks directly with your Google Drive Account and open/create stacks from Google Drive.',
    category: 'Apps',
    status: 0,
  },
  {
    id: 10,
    name: 'Google Chrome Extension',
    description: 'Clip information from any webpage, through a custom google chrome extension.<a href="https://chrome.google.com/webstore/detail/stackby-webclipper/kjkhpjfgbiedbaohfklagjmcdjhamoje" > Download it from here.</a>',
    category: 'Apps',
    status: 0,
  },
  {
    id: 11,
    name: 'Color Formatting on Rows',
    description: 'Add colors on rows based on pre-defined conditions. ',
    category: 'Data Transformation',
    status: 0,
  },
  {
    id: 12,
    name: 'Database Snapshots',
    description: 'Take a manual, point-in-time snapshot of your database and recover it at a later time. Note: Duration for snapshot history is based on the plans. ',
    category: 'Data Recovery',
    status: 1,
  },
],

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

这是我的 json 文件代码

这是 .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>
            </div>
        </div>
      </div>
    <%}-%>
  </div>
</div>

在这里,我想显示在 Download it from here.', 作为下载链接,但它显示整个 url ,

【问题讨论】:

  • “json 对象代码”真的是 JSON 文件中的代码吗?
  • 是的@evolutionxbox
  • 您不能将a 放在a 中。试试别的方法。只要浏览器看到&lt;a&gt;&lt;a&gt;,你就会得到&lt;a&gt;&lt;/a&gt;&lt;a&gt;
  • @deepakj 代码不是 JSON。它看起来像 javascript。
  • 它不是@skobaljic 的内部

标签: javascript html jquery node.js ejs


【解决方案1】:

使用ejs模板,

你可以输出原始数据(打印 html) 使用&lt;%- your.rentry %&gt; 而不是&lt;%= your.rentry %&gt;

正如您在documentation 中看到的那样:

<%= Outputs the value into the template (HTML escaped)
<%- Outputs the unescaped value into the template

所以你最后的描述应该是这样的:

<div class="card-body">
     <p class="card-text" ><%- powerUpList[i].description %></p>
</div>

【讨论】:

  • 它正在工作,但是,我的手风琴没有崩溃,它总是打开
  • 与打印问题无关,我想你错过了导入bootstrap js
猜你喜欢
  • 2021-12-14
  • 2016-03-17
  • 1970-01-01
  • 2019-01-24
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-02-22
  • 1970-01-01
相关资源
最近更新 更多