我使用 GWT CellList 小部件来呈现 Cell 元素。
有没有办法在渲染完成后注册渲染完成或渲染完成事件来执行东西?
我有同样的问题,并查看了我找到可能的解决方案的代码。
在其中HasDataPresenter
有将单元格呈现到视图中的代码(方法resolvePendingState(JsArrayInteger modifiedRows)
:
if (redrawRequired) {
// Redraw the entire content.
SafeHtmlBuilder sb = new SafeHtmlBuilder();
view.replaceAllChildren(newState.rowData, selectionModel, newState.keyboardStealFocus);
view.resetFocus();
} else if (range0 != null) {
// Surgically replace specific rows.
// Replace range0.
{
int absStart = range0.getStart();
int relStart = absStart - pageStart;
SafeHtmlBuilder sb = new SafeHtmlBuilder();
List<T> replaceValues = newState.rowData.subList(relStart, relStart + range0.getLength());
view.replaceChildren(replaceValues, relStart, selectionModel, newState.keyboardStealFocus);
}
// Replace range1 if it exists.
if (range1 != null) {
int absStart = range1.getStart();
int relStart = absStart - pageStart;
SafeHtmlBuilder sb = new SafeHtmlBuilder();
List<T> replaceValues = newState.rowData.subList(relStart, relStart + range1.getLength());
view.replaceChildren(replaceValues, relStart, selectionModel, newState.keyboardStealFocus);
}
view.resetFocus();
方法 view.replaceAllChildren(....) 调用渲染单元格的渲染方法,并在完成时触发 ValueChangeEvent()。
@Override
public void replaceAllChildren(....) {
SafeHtml html = renderRowValues(...);
....
fireValueChangeEvent();
}
因此,在您的 cellList 中,您应该执行以下操作:
cellList.addHandler(new ValueChangeHandler<List<IPost>>() {
@Override
public void onValueChange(ValueChangeEvent<List<IPost>> event) {
//Do something
//Be careful because this handler could be called from other methods
}
}, ValueChangeEvent.getType());
您可以使用自己的自定义 Cell 扩展 AbstractCell(如示例中使用的 ContactCell)。
在那里,您将需要覆盖渲染方法:
@Override public void render(Context context, ContactInfo value, SafeHtmlBuilder sb) {
(//other codes)
(// put your logic after render here at the last)
}