稍微迭代(for循环)

Man*_*sha 5 iteration for-loop aem sightly

<c:forEach>在jstl中使用过.现在我想要使用.

我的用例是打印1到10之间的数字,然后我如何for loop在java中轻松迭代

Cpt*_*der 9

很明显不会让你在设计中加入任何逻辑.您应该做的是,您应该自定义基础模型,以便您可以检索包含需要显示的数据的不相关(从Sightly的角度来看)长度的准备列表.在那之后,只需使用data-sly-list.您需要谷歌获取更多详细信息,但一般来说,这就是您在Sightly中使用列表的方式:

<ul data-sly-list.myitem="${mymodel.myitems}" data-sly-unwrap>
  <li>${myitem.foo}</li>
</ul>
Run Code Online (Sandbox Code Playgroud)

编辑:正如@nateyolles指出的那样,你可以通过在测试条件(使用索引遍历项目的具体范围<li data-sly-test="${itemList.count >= 2 && itemList.count <= 6}">${item}</li>),但我不知道这是否是"悦目的方式".就个人而言,我建议不要这样做,除非它会让你的生活变得更加容易.


kau*_*hni 5

请有此AEM论坛poat一乐: - http://help-forums.adobe.com/content/adobeforums/en/experience-manager-forum/adobe-experience-manager.topic.html/forum__wtot-hi_i_need_toite.html

循环播放固定数量的项目

<ul data-sly-list="${ [1,2,3,4] }">
<li>${item}</li>
</ul>
Run Code Online (Sandbox Code Playgroud)

也请看一下文档:

链接:-https: //docs.adobe.com/docs/zh/aem/6-1/develop/sightly/block-statements.html

//

清单

data-sly-list:对提供的对象中的每个可枚举属性重复host元素的内容。

这是一个简单的循环:

<dl data-sly-list="${currentPage.listChildren}">
    <dt>index: ${itemList.index}</dt>
    <dd>value: ${item.title}</dd>
</dl>
Run Code Online (Sandbox Code Playgroud)

代码样本仅用于说明目的。

以下默认变量在列表范围内可用:

item:迭代中的当前项目。

itemList:具有以下属性的对象:

索引:从零开始的计数器(0..length-1)。

count:基于一个的计数器(1..length)。

first:如果当前项是第一项,则为true。

middle:如果当前项目既不是第一项也不是最后一项,则为true。

last:如果当前项目是最后一项,则为true。

奇数:如果索引为奇数,则为true。

偶数:如果索引为偶数,则为true。

//

<ul data-sly-list.child="${currentPage.listChildren}">
  <li class="${ childList.odd ? 'odd' : 'even'}">${child.title}</li>
</ul>
Run Code Online (Sandbox Code Playgroud)

//

<div data-sly-list.children="${resource.listChildren}">
    <div data-sly-list.fields="${children.listChildren}">
        <div data-sly-test=${fieldsList.last}> DO SOMETHING BEFORE LAST NODE</div>
        <div data-sly-resource="${fields.path}"></div>
    </div>
</div>
Run Code Online (Sandbox Code Playgroud)

因此,根据您的用例,您可以使用:

<ul data-sly-list.child="${currentPage.listChildren}">
   <li data-sly-test="${childList.index <= 5}">${child.title}</li>
</ul>
Run Code Online (Sandbox Code Playgroud)

希望这对您有用。

谢谢并恭祝安康

考图克·萨尼(Kautuk Sahni)