首页 > 解决方案 > GXT 如何在 XTemplate 中显示树对象?

问题描述

我有以下问题:我在一个复杂的 XTemplate 中显示我的 GXT 项目的数据。

@XTemplate(source = "DepictionDisplay.html")
    SafeHtml displayoben(String shortName, String inventoryNumber, String cave, String wall, String expedition, String vendor, String purchaseDate, String currentLocation, String stateOfPreservation, SafeUri imageUri, SafeUri fullImageUri,
            SafeUri realCaveSketchUri, double width, double height, String style, String modeOfRepresentation, String description, String generalRemarks, String otherSuggestedIdentifications); 

DepictionDisplay.html 的相关部分是:

            <table class="data-view">
                <tpl if="inventoryNumber != &quot;&quot;">
                <tr style="border-bottom: 1px solid black">
                        <td class="data-view-left"><i>Inventory No.</i></td>
                        <td class="data-view-right">{inventoryNumber}</td>
                </tr>
                </tpl>
                <tpl if="cave != &quot;&quot;">
                <tr style="border-bottom: 1px solid black">
                        <td class="data-view-left"><i>Located in Cave</i></td>
                        <td class="data-view-right">{cave}</td>

                </tr>
                </tpl>
                <tpl if="wall != &quot;&quot;">
                <tr style="border-bottom: 1px solid black">
                        <td class="data-view-left"><i>Position in cave</i></td>
                        <td class="data-view-right">{wall}</td>
                </tr>
                </tpl>
                <tpl if="expedition != &quot;&quot;">
                <tr style="border-bottom: 1px solid black">
                        <td class="data-view-left"><i>Acquired by expedition</i></td>
                        <td class="data-view-right">{expedition}</td>
                </tr>
                </tpl>
                <tpl if="vendor != &quot;&quot;">
                <tr style="border-bottom: 1px solid black">
                        <td class="data-view-left"><i>Vendor</i></td>
                        <td class="data-view-right">{vendor}</td>
                </tr>
                </tpl>
                <tpl if="purchaseDate != &quot;&quot;">
                <tr style="border-bottom: 1px solid black">
                        <td class="data-view-left"><i>Purchase Date</i></td>
                        <td class="data-view-right">{purchaseDate}</td>
                </tr>
                </tpl>
                <tpl if="currentLocation != &quot;&quot;">
                <tr style="border-bottom: 1px solid black">
                        <td class="data-view-left"><i>Current location</i></td>
                        <td class="data-view-right">{currentLocation}</td>
                </tr>
                </tpl>
                <tpl if="stateOfPreservation != &quot;&quot;">
                <tr style="border-bottom: 1px solid black">
                        <td class="data-view-left"><i>State of preservation</i></td>
                        <td class="data-view-right">{stateOfPreservation}</td>
                </tr>
                </tpl>
                <tpl if="style != &quot;&quot;">
                <tr style="border-bottom: 1px solid black">
                        <td class="data-view-left"><i>Style</i></td>
                        <td class="data-view-right">{style}</td>
                </tr>
                </tpl>
                <tpl if="modeOfRepresentation != &quot;&quot;">
                <tr style="border-bottom: 1px solid black">
                        <td class="data-view-left"><i>Mode of representation</i></td>
                        <td class="data-view-right">{modeOfRepresentation}</td>
                </tr>
                </tpl>
        </table>

问题是,最近,我不得不将wall的前字符串值更改为树对象。树对象的条目具有用于向下导航的 getchildren() 函数和用于访问要显示的字符串值的 getText() 函数。

我现在的问题是:如何在此表中显示树对象?到目前为止,我还没有找到合适的选项,因为树的深度可以变化。

任何想法都会受到赞赏。

真挚地,

埃里克

标签: javagwtgxt

解决方案


XTemplates 可以接受SafeHtml参数并插入该内容,并支持调用简单的格式化函数,但不能递归调用它们自己或其他函数。

考虑遍历它getChildren()并将它们的每个渲染模板附加到 a SafeHtmlBuilder,然后将生成的 SafeHtml 字符串传递给父级。然后您自己的代码进行递归,将较小的内容插入较大的内容。


推荐阅读