2
所有的問題,我怎樣才能創建一個自定義單元格上使用GWT CellTable它的畫布?如何使用畫布作爲GWT單元格的單元格?
我搜索一種將畫布轉換爲html的方式,將其附加到render方法的SafeHtmlBuilder參數中,但沒有成功。下面是自定義單元格的有趣片段:
public void render(Context context, String value, SafeHtmlBuilder sb) {
Canvas c = Canvas.createIfSupported();
// create a text into the canvas using the value parameter
// something like (this is not important) :
c.getContext2d().drawTheText(value);
// here is the problem, what kind of transformation may I do
// to use the canvas in this cell ?
SafeHtml safeValue = SafeHtmlUtils.fromString(c.?????);
sb.append(safeValue);
}
編輯:這裏是工作的解決方案,這要歸功於托馬斯
sb.append(SafeHtmlUtils.fromTrustedString("<img src=\"" + canvas.toDataUrl() + "\" />"));
注意,模板應使用而不是直接使用了一塊的html代碼。
哼,看起來很奇怪,但我會試一試。謝謝 –
的工作,非常感謝 –
如果我是你,我會衡量表演。如果您改爲創建佔位符元素(使用ID)並安排延遲命令以使用Canvas填充佔位符,則對用戶可能會更好。這樣,'CellTable'渲染的其餘部分就不會受到畫布表現的影響。 –