我想在 UIBinder 中使用以下内容,以便我可以以编程方式设置href
我的代码中的链接。
<g:HTMLPanel>
<g:Anchor ui:field="link">
<g:InlineLabel ui:field="firstName"/>
<g:InlineLabel ui:field="lastName"/>
</g:Anchor>
</g:HTMLPanel>
当我尝试这个时,我得到:
ERROR: Found widget in an HTML context Element <g:InlineLabel ui:field='firstName'> (:7).
如何将小部件嵌入锚点内?以前我曾使用过:
<a id="myAnchor">
etc...
</a>
然后在我的代码中操作 DOM 来设置 HREF,但这很丑陋。有没有更好的办法?
下面的类的行为与 SimplePanel 完全相同(即,您可以在其中放置一个小部件),但使用“a”而不是“div”。如果您需要更多小部件,只需在其中放置另一个面板即可。
import com.google.gwt.user.client.DOM;
import com.google.gwt.user.client.ui.SimplePanel;
public class Link extends SimplePanel {
public Link() {
super(DOM.createAnchor());
}
private void setHref(String href) {
getElement().setAttribute("href", href);
}
private String getHref() {
return getElement().getAttribute("href");
}
public void setTarget(String frameName) {
getElement().setAttribute("target", frameName);
}
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)