从underscore.js中的模板中删除html元素

时间:2014-02-19 11:00:42

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

我的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

之前从{{1}}节点移除锚标记

2 个答案:

答案 0 :(得分:0)

我不完全确定“来自描述”的含义,但您可以使用<% if (condition) {%>有条件地包含某些内容。我只想猜你的意思。如果不是这样,你必须更清楚......

更新

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

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

答案 1 :(得分:0)

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


$(“。description p a”)。remove(); //使用jquery