如何在返回一定数量的记录后停止循环?

时间:2015-06-16 19:04:07

标签: javascript html freemarker

我希望在返回8条记录后停止FreeMarker中的循环。到目前为止,我有以下代码

<#ftl ns_prefixes={"content":"http://purl.org/rss/1.0/modules/content/","dc":"http://purl.org/dc/elements/1.1/"}>
    <#list kiblogs.rss.channel.item as item>
        <div class="span4">
            <div class="panel">
                <img src="${item.thumbnail.@@nested_markup}" class="title-image"> 
                <div class="top-content">
                    <h3>${item.title}</h3>
                    <div class="datetime">${item.pubDate?substring(0, 16)}</div>
                    <div class="analyst">${item["dc:creator"]}</div>
                    <p class="ellipsis multiline">${item.description}</p>
                    <div class="bottom-blue-buttn">
                        <a class="launch" attrId="${item.uid}">Read the blog</a>
                    </div>                  
                </div>
            </div>
        </div> 
        <hr>            
</#list>

1 个答案:

答案 0 :(得分:0)

我通过添加

解决了这个问题
<#if item_index==8><#break></#if>  

所以我的代码现在是

<#ftl ns_prefixes={"content":"http://purl.org/rss/1.0/modules/content/","dc":"http://purl.org/dc/elements/1.1/"}>

      <#list kiblogs.rss.channel.item as item>
          <div class="span4">
            <div class="panel">
              <img src="${item.thumbnail.@@nested_markup}" class="title-image"> 
                <div class="top-content">
                  <h3>${item.title}</h3>
                  <div class="datetime">${item.pubDate?substring(0, 16)}</div>
                  <div class="analyst">${item["dc:creator"]}</div>
                  <p class="ellipsis multiline">${item.description}</p>
                  <div class="bottom-blue-buttn"><a class="launch" attrId="${item.uid}">Read the blog</a></div>                  
                </div>

            </div>
           </div> 

        <hr>
       <#if item_index==8><#break></#if>              
      </#list>