问题描述
我正在为我的应用程序使用 GWT 和 UiBinder,我正在尝试这样做
I'm using GWT and UiBinder for my app, and I'm trying to do this
<g:TextBox ui:field="searchBox" styleName="{style.searchBox}" placeholder="search"/>
但是自定义 placeholder
属性将不起作用,因为 TextBox
上没有 setPlaceholder
方法 - 我需要这样做:
But the custom placeholder
attribute won't work because there isn't a setPlaceholder
method on TextBox
- I need to this:
searchBox.getElement().setAttribute("placeholder", "search");
回到java代码.关于如何在 UiBinder 本身中执行此操作的任何想法?我想我可以将其更改为普通输入元素并尝试获取引用及其值,但我宁愿不走那条路.
back in the java code. Any ideas on how to do this in UiBinder itself? I suppose I could change it over to a normal input element and try to grab a reference and its value, but I'd rather not go down that road.
推荐答案
创建自定义 SearchBox
怎么样,使用方法 setPlaceholder(String placeholder)TextBox
/代码> ?
What about creating custom SearchBox
that extends TextBox
with method setPlaceholder(String placeholder)
?
然后在 UiBinder 中:
Then in UiBinder:
<custom:SearchBox ui:field="searchBox" styleName="{style.searchBox}"placeholder="search"/>
这篇关于UiBinder 小部件中的自定义属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!