aem - 从吊索模型获取列表到 HTML 页面的 HTL 代码
问题描述
我创建了 Sling 模型,它正在获取根页面及其子页面。我在 List 中添加了所有页面的标题和描述。
我的豆类如下
Items(String title, String description, List<Items>)
Items
我在我的吊索模型中
有这个 bean 类的列表,并在这个列表中添加了内容。List<Items>
in 参数用于将子页面存储在其中。
如何在我的 HTL 代码中获取此列表值以在页面上使用视觉显示它?这将是什么代码?
解决方案
您通常会使用 getter 方法公开时间列表:
public List<Items> getItems() { ... }
假设每个项目还公开了title
和的吸气剂description
:
public String getTitle() { ... }
public String getDescription() { ... }
然后你可以使用你的模型:
<ul data-sly-use.myModel="MyModelClass" data-sly-list="myModel.items">
<li>${item.title} - ${item.description}</li>
</ul>
HTL 规范中还有更多示例。
推荐阅读
- mysql - where 语句中不存在别名表
- sed - 使用 Sed 使用带有模式的文件删除多行
- javascript - 使用异步等待 es6 函数在变量上未定义
- html - 你可以使用 HTML 作为背景,因为你可以使用 SVG 作为背景吗?
- stm32 - 多从机到单主机 SPI 软件从机管理的工作原理
- html - 打印 JSON 字符串并使用 HTML 和 CSS 对其进行格式化
- r - 如何从 data.frame 创建因子变量并在并排图中绘制列
- python - 如果在 Django 的两个字段之一中相关
- javascript - ReactJS 中的列表和键:TypeError:无法读取未定义的属性“映射”
- c++ - 如何在类中创建二维数组元素,然后在其构造函数中指定其维度?