首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在HTL中呈现列表

在HTL中呈现列表
EN

Stack Overflow用户
提问于 2022-11-04 19:55:31
回答 1查看 31关注 0票数 -1

我有一个表,需要呈现它的行和列。我能够正确地看到CRXDE上的数据,但我无法在HTL上呈现它。

下面是java类:

代码语言:javascript
复制
public class Table {
    
        @ChildResource
        private List<TableRow> tableRowList;
    }
    
    public class TableRow
    {
        @ValueMapValue
        private String key;
        @ChildResource
        private List<TableColumn> tableColumnList;
    }
    
    public class TableColumn
    {
        @ValueMapValue
        private String colValue;
    }

以下是简化的HTL:

代码语言:javascript
复制
<sly data-sly-use.model="models.Table"
    <table class="table">
            <tbody>
            <sly data-sly-list="${model.tableRowList}">
                <tr>
                    <th>${item.key @context='html'}</th>
                    <th data-sly-repeat.colValue="${item.tableColumnList}">${colValue @context='html'}</th>
                </tr>
            </sly>
            </tbody>
        </table>
</sly>

key 被正确地呈现,但不是每一行的列列表。当我检查CRXDE时,数据按预期存储。

知道出了什么问题吗?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2022-11-08 07:16:00

您需要在colValue上显式调用TableColumn属性,我重构了HTL/Sightly片段,以更好地显示哪个变量是哪种类型/类:

代码语言:javascript
复制
<table class="table" data-sly-use.table="models.Table">
    <tbody>
        <tr data-sly-repeat.tableRow="${table.tableRowList}">
            <th>${tableRow.key @context='html'}</th>
            <th data-sly-repeat.tableColumn="${tableRow.tableColumnList}">${tableColumn.colValue @context='html'}</th>
        </tr>
    </tbody>
</table>

PS:我强烈建议您不要访问这样的私有属性,而是通过getter公开它们。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/74322341

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档