如本页链接所述,我已经在 GWT 中使用 UiRenderer 创建了 CellRenderer 。一切正常,只是我不知道如何重置该列表中的所有元素,这是我的代码。
查看类:
/**
* Created by ashish on 2/23/15.
*/
public class SimpleListCell extends AbstractCell<NewsDto> {
public interface SimpleListCellRenderer extends UiRenderer {
void render(SafeHtmlBuilder sb,String title,String description);
void onBrowserEvent(SimpleListCell newsCell, NativeEvent event, Element parent, NewsDto value);
SpanElement getDescriptionSpan(Element parent);
}
private static SimpleListCellRenderer uiNewsCellRenderer = GWT.create(SimpleListCellRenderer.class);
public SimpleListCell(){
super("click");
}
@Override
public void onBrowserEvent(Context context, Element parent, NewsDto value,
NativeEvent event, ValueUpdater<NewsDto> updater) {
uiNewsCellRenderer.onBrowserEvent(this, event, parent, value);
}
@Override
public void render(Context context, NewsDto newsDto, SafeHtmlBuilder safeHtmlBuilder) {
String title = newsDto.getTitle();
String description = newsDto.getShortDescription();
uiNewsCellRenderer.render(safeHtmlBuilder,title,description);
}
@UiHandler({"selectedNews"})
void onSelectNews(ClickEvent event,Element parent,NewsDto value){
GWT.log(value.getDescription());
uiNewsCellRenderer.getDescriptionSpan(parent).setInnerText(value.getDescription());
}
}
UiBinder 类。
<ui:UiBinder xmlns:ui='urn:ui:com.google.gwt.uibinder'
xmlns:g='urn:import:com.google.gwt.user.client.ui'>
<ui:with field="title" type="java.lang.String"/>
<ui:with field="description" type="java.lang.String" />
<ui:style>
</ui:style>
<div >
<span ui:field="selectedNews">
<h3><ui:text from="{title}" /> </h3>
<p><span ui:field="descriptionSpan"><ui:text from="{description}"/></span></p>
<hr/>
</span>
</div>
</ui:UiBinder>
现在,当我单击某个新闻项目时,它正在用大描述更新描述,但我想重置其余新闻的描述。任何想法如何实现这一目标。