【问题标题】:remove html element from the template in underscore.js从 underscore.js 的模板中删除 html 元素
【发布时间】:2014-02-19 11:00:41
【问题描述】:

我的 JSON 响应是这样的:

{
          "description": "discription about the feaure will come here.  <a href=\"http://example.com\" target=\"_blank\">Learn more</a>",
          "largeIconURL": "some_path/ico_someicon.gif",
          "displayName": "feature one"
        },
        {
          "description": "discription about the feaure will come here.",
          "largeIconURL": "some_path/ico_someicon.gif",
          "displayName": "feature two"
        },
        {
          "description": "discription about the feaure will come here. ",
          "largeIconURL": "some_path/ico_someicon.gif",
          "displayName": "feature three"
        },

我的模板是这样的

<%
        _.each(items,function(item, key, list){
      %>
      <li>
        <div class="oneSpec">

          <div class="description">
            <h4><%= item.displayName %></h4>
            <p><%= item.description %></p>
          </div>
        </div>
      </li>

      <%
        });
      %>

如何在将 description 节点绘制到 DOM 之前删除锚标记

【问题讨论】:

  • 要去掉description绝对不写!

标签: javascript underscore.js underscore.js-templating


【解决方案1】:

我不完全确定您所说的“来自描述”是什么意思,但您可以使用 &lt;% if (condition) {%&gt; 有条件地包含某些内容。我只是猜测你的意思。如果不是这样,那你得说清楚点……

更新:

像这样移除锚点 (Regex in Javascript to remove links):

<%=item.description.replace(/<a\b[^>]*>(.*?)<\/a>/i,"")) %>

【讨论】:

【解决方案2】:

其中一种方法是: 渲染后, 使用


$(".description p a").remove(); //使用jquery

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-09-01
    • 2021-10-02
    • 2015-10-13
    • 1970-01-01
    • 2015-04-28
    • 2012-04-07
    • 2013-12-04
    相关资源
    最近更新 更多