英文:
GXT how to display a tree-object in a XTemplate?
问题
我有以下问题:
我正在在我的GXT项目中展示数据,使用了一个非常复杂的XTemplate。
```java
@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 != ''">
<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 != ''">
<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>
<!-- 其他字段类似,省略 -->
</table>
问题在于,最近我不得不将以前的wall字符串值更改为树对象。
树对象的条目具有getchildren()函数以向下导航,以及一个getText()函数以访问要显示的字符串值。
我的问题是:如何在此表格中显示树对象?到目前为止,我没有找到合适的选项,因为树的深度可以变化。
非常感谢任何想法。
诚挚地,
Erik
<details>
<summary>英文:</summary>
I have the following problem:
I am displaying Data of my GXT-project in a rever complex XTemplate.
@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);
The relevant part of DepictionDisplay.html is:
<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>
The Problem is, that lately, I had to change the former String Value of **wall** to a tree-object.
The entries of the tree object have a getchildren() function to navigate down and a getText() function to access the String value, which is to be displayed.
My question is now: How can I display a Tree-Object inside this Table? So far, I did not find a suitable option as the tree can have a changing depth.
Any Ideas are more then appreciated.
Sincerely,
Erik
</details>
# 答案1
**得分**: 0
XTemplates可以接受`SafeHtml`参数,插入该内容,并支持调用简单的格式化函数,但不能递归调用自身或其他函数。
考虑遍历`getChildren()`并将它们的渲染模板附加到`SafeHtmlBuilder`,然后将生成的SafeHtml字符串传递给父级。然后,您的代码执行递归,将较小的内容插入较大的内容。
<details>
<summary>英文:</summary>
XTemplates can take `SafeHtml` params, and insert that content, and have support for calling simple formatting functions, but cannot call themselves or other functions recursively.
Consider iterating through that `getChildren()` and appending each of their rendered template to a `SafeHtmlBuilder`, then pass the resulting SafeHtml string to the parent. Your own code then does the recursion, inserting smaller bits of content into bigger ones.
</details>
专注分享java语言的经验与见解,让所有开发者获益!
评论