我只想做这样的事情:
contentAsync.load("linear_regression", new AsyncCallback<String>() {
public void onFailure(Throwable caught) {
content.add(new HTML("<h1>FAIL</h1>something went wrong"));
caught.printStackTrace();
}
public void onSuccess(String result) {
// after the RPC new mathematical equations were added to the web content
// so now I invoke the JavaScript function 'testFunc' on the client.
MainLayout.jsniAlert("testFunc");
}
});JavaScript部分:
<script type="text/javascript">
function testFunc() {
alert('huhu');
MathJax.... <--! reload page -->
}
</script>我只需要知道是否以及如何才能告诉MathJax重新加载页面。我找不到这样的例子。我已经试过了
MathJax.Hub.Process();
MathJax.Hub.Update();
MathJax.Hub.Reprocess();
MathJax.Hub.Rerender();但是没有一个call能达到我所希望的效果。谢谢你的帮助
发布于 2013-04-03 05:07:47
要对排版操作进行排队,请使用以下命令
MathJax.Hub.Queue(["Typeset",MathJax.Hub]);
这将导致MathJax在下一次能够这样做时排版页面。它保证了排版将与jax、扩展、字体、样式表和其他异步活动的加载正确地同步,并且是请求MathJax处理额外材料的唯一真正安全的方法。
MathJax.Hub.Typeset()命令还接受一个参数,该参数是一个内容要排版的DOM元素。它可以是一个段落、一个元素,甚至是一个MathJax数学标签。它也可以是这样一个对象的DOM id,在这种情况下,MathJax将为您查找DOM元素。所以
MathJax.Hub.Queue(["Typeset",MathJax.Hub,"MathExample"]);
将对id为MathExample的元素中包含的数学进行排版。
发布于 2013-04-04 01:19:58
我是如何实现它的(使用Google Web Toolkit):
JavaScript函数:
<!-- Refresh MathJax syntax -->
<script type="text/javascript">
function reloadMathJax() {
MathJax.Hub.Queue(["Typeset",MathJax.Hub]);
}
</script>通过声明本机方法reloadMathJax(),将其称为客户端
public class EW implements EntryPoint {
final RootPanel root = RootPanel.get("root");
@Override
public void onModuleLoad() {
// ...
}
public static final native void reloadMathJax()/*-{
$wnd.reloadMathJax();
}-*/;
}然后在需要的地方调用它:
public void load(final VerticalPanel target,
String file, final Successor success) {
contentAsync.load(file, new AsyncCallback<String>() {
public void onFailure(Throwable caught) {
target.add(new HTML("<h1>FAIL</h1>something went wrong"));
caught.printStackTrace();
}
public void onSuccess(String result) {
if (result == null) {
target.add(new HTML(
"Could not load content from server. (RPC returned null)"));
return;
}
HTMLPanel panel = new HTMLPanel(result);
success.onSuccess(panel);
target.add(panel);
EW.reloadMathJax();
}
});
}https://stackoverflow.com/questions/15766994
复制相似问题