我正在尝试使用在 UI Binder 模板中定义的 a 来初始化 aTreeItem
作为Widget
的TreeItem
内容。最初我从这样的模板开始:
<g:Tree>
<g:TreeItem>
<g:HTMLPanel>
<p>This is the root item's content.</p>
</g:HTMLPanel>
<g:TreeItem>
<g:HTMLPanel>
<p>This is the child's content.</p>
</g:HTMLPanel>
</g:TreeItem>
</g:TreeItem>
</g:Tree>
期望最终得到一个像这样的树结构:
+ This is the root item's content.
扩展为:
- This is the root item's content.
\ This is the child's content.
但这不起作用。这些HTMLPanel
小部件是作为TreeItem
s 的子级创建的,而不是作为项目的小部件,所以我最终得到了这样的结构:
- (root item has no content)
\ This is the root item's content.
- (first child has no content)
\ This is the child's content.
所以我尝试像这样扩展TreeItem
类:
public class WidgetTreeItem extends TreeItem {
@UiChild(tagname="widget", limit=1)
public void setWidget(IsWidget isWidget) {
super.setWidget(isWidget.asWidget());
}
}
然后,将包含的包WidgetTreeItem
导入c
命名空间,我有一个这样的模板:
<g:Tree>
<c:WidgetTreeItem>
<c:widget>
<g:HTMLPanel>
<p>This is the root item's content.</p>
</g:HTMLPanel>
</c:widget>
<!-- Should create a child TreeItem with the HTMLPanel as its Widget. -->
<g:HTMLPanel>
<p>This is the child's content.</p>
</g:HTMLPanel>
</c:WidgetTreeItem>
</g:Tree>
但这也行不通。它失败,但有以下异常:
Only TreeItem or Widget subclasses are valid children: <c:WidgetTreeItem>
.
谁能看到如何实现我正在尝试的目标?