如何轻松地迭代对象列表?

0 adobe aem sightly

我创建了一个getmyPages()返回的Java类方法iterator<Page>.现在在HTML页面中,我能够实例化该类并访问该类的其他属性.

但是,我希望迭代这个迭代器的方式currentPage.listChildren工作.....

因为currentPage.listChildren回报iterator<Page> 我也回来了.

但是我无法......我正在打印的HTML标签是空的.

Sha*_*ppa 5

您可以使用data-sly-listattribute遍历迭代器.这是Feike Visser的 Sightly教程的摘录:

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

data-sly-unwrap 属性可用于防止循环的封闭标记成为最终标记的一部分

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

链接到教程:http://blogs.adobe.com/experiencedelivers/experience-management/sightly-intro-part-1

文档data-sly-list:链接