GWT UiBinder 有什么方法可以拥有动态的小部件列表吗?
类 Foo
有一个变量 List
Class Foo
has a variable List<Button> bar
, how can I render each of the buttons using UiBinder? Is it even possible?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
UiBinder 是一个用于以声明方式布局小部件的 XML 模板,并且不是渲染器。因此,UiBinder XML 中不能有条件、循环和其他逻辑结构。
相反,您可以做的是在 UiBinder 中设置一个面板,作为您希望所有按钮所在位置的占位符。在您的 Java 类中有对此面板的 ui:field 引用。循环遍历按钮列表并使用字段句柄在 java 代码中将按钮添加到面板。
另一种方法是定义一个组合并将其添加到 UiBinder 中,然后让组合自行渲染按钮。只是取决于什么最适合您的设计。
UiBinder is a XML template for declaratively laying out widgets and is not a renderer. Hence you cannot have conditionals, loops and other logical constructs within the UiBinder XML.
What you can instead do is have a Panel in the UiBinder as mere placeholder for where you would like all your buttons to go. Have a ui:field reference to this panel in your Java class. Loop through the button list and add buttons to the panel in java code, using the field handle.
Other approach would be to define a composite and add the composite in the UiBinder, and let the composite do the rendering of the buttons by itself. Just depends on what is best suitable for your design.