我如何添加唯一的ID到自定义单元格? [英] How can I add unique id to a custom cell?
问题描述
我知道我可以这样做:
@Override
public void render(Context context, TreeElement value,SafeHtmlBuilder sb){
if(value == null){return;}
sb.appendHtmlConstant(< div id = \+ value.getID()+\ >+
value.getName())+< / div>;
}
但是我想用类似EnsureDebugID()的东西,不得不刻录代码中的ID。有没有办法做到这一点?
我会在上述两种方法之间做些什么。您一定要添加一个前缀以确保您可以在测试期间轻松识别这些单元格,并且您还应该使用 createUniqueId()
方法而非
<@ p $ p> @Override
public void render(Context context,TreeElement value, SafeHtmlBuilder sb){
if(value == null){return;}
String id = Document.get()。createUniqueId();
sb.appendHtmlConstant(< div id = \cell _+ id +\>+
value.getName())+< / div>;
}
In a gwt project I have a CellTree with custom cells. For easier testing I would like to add IDs for each of the cells. I know I can make it like this :
@Override
public void render(Context context,TreeElement value, SafeHtmlBuilder sb) {
if (value == null) {return;}
sb.appendHtmlConstant("<div id=\""+value.getID()+"\">" +
value.getName()) + "</div>";
}
But I would like to use something similar to EnsureDebugID() so I don't have to burn the IDs in the code. Is there a way to do that?
I would do something between the two of the aforementioned approaches. You should definitely add a prefix to be sure you can easily identify the cells during testing, and you should also take the createUniqueId()
approach rather than generating your own UUIDs which can be more troublesome.
@Override
public void render(Context context, TreeElement value, SafeHtmlBuilder sb) {
if (value == null) {return;}
String id = Document.get().createUniqueId();
sb.appendHtmlConstant("<div id=\"cell_"+id+"\">" +
value.getName()) + "</div>";
}
这篇关于我如何添加唯一的ID到自定义单元格?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!