问题描述
当我使用
$ b
当 UiBinder 将一个窗口小部件看作 HTMLPanel ,它会生成一个占位符< span> 并生成唯一的ID,然后使用 HTMLPanel.addAndReplaceElement 来
所以第二个片段会产生(大约)
HTMLPanel root = new HTMLPanel(< span id ='uuid'>< / span>);
HTMLPanel child = new HTMLPanel(/ * Widgets,more HTML。* /);
root.addAndReplaceElement(child,uuid);
Is there some sort of penalty when I'm using a HTMLPanel instead of a plain div?
E.g.
<g:HTMLPanel> <div> /* Widgets, more HTML */ </div> </g:HTMLPanel>
in contrast to
<g:HTMLPanel> <g:HTMLPanel> /* Widgets, more HTML */ </g:HTMLPanel> </g:HTMLPanel>
Short answer:
When in doubt, look at the generated code (pass the -gen argument to the DevMode or Compiler)
Long answer:
There will be a runtime performance penalty using a widget over a simple DOM element, always. And even more when that DOM element is created by parsing an HTML snippet.
When UiBinder sees a widget as a child of HTMLPanel, it will generate a placeholder <span> with a generate unique ID and then use the HTMLPanel.addAndReplaceElement to replace that placeholder with a widget.
So the second snippet will generate (approx)
HTMLPanel root = new HTMLPanel("<span id='uuid'></span>"); HTMLPanel child = new HTMLPanel("/* Widgets, more HTML. */"); root.addAndReplaceElement(child, "uuid");
这篇关于UiBinder - HTMLPanel与div的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!