![](/img/trans.png)
[英]Ruby on Rails & MathJax - how do I force page reload so my mathjax will render?
[英]Let mathjax reload page after an rpc
我只想做这样的事情:
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();
但是没有电话希望我这样做。 谢谢你的帮助
从MathJax文档中 :
要使排版操作排队,请使用以下命令
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的元素中包含的数学。
我的实现方式(使用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();
}
});
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.