问题描述
Class Foo
有一个变量 List< Button> bar
,如何使用UiBinder渲染每个按钮?它甚至有可能吗?UiBinder是用于声明性地布置小部件的模板 >不是渲染器。因此,您不能在UiBinder XML中使用条件语句,循环语句和其他逻辑结构。
你可以做的是在UiBinder中只有一个Panel作为占位符,像你所有的按钮去。在你的Java类中有一个ui:字段引用。循环访问按钮列表,并使用字段句柄将按钮添加到java代码的面板中。
另一种方法是定义一个组合并在UiBinder中添加组合,让组合自己完成按钮的渲染。取决于什么最适合您的设计。
Class Foo
has a variable List<Button> bar
, how can I render each of the buttons using UiBinder? Is it even possible?
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.
这篇关于GWT的UiBinder的任何方式有动态的Widgets列表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!