簡體   English   中英

在rpc之后讓mathjax重新加載頁面

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM