1

我想使用 javascriptcallback 更新对 javascript 函数的输入。推送到客户端的 addInput.js 脚本中的 javascript 代码在从 onAjaxEvent 调用触发时不会执行,但在从 afterRender 调用时可以正常工作。

代码如下所示:

public void onAjaxEvent(final String input) {
  ajaxResponseRenderer.addCallback(new JavaScriptCallback() {
    public void run(JavaScriptSupport jss_) {
      addInput(jss_, input);/* javascript never gets executed */
    }
  });
}
protected void addInput(JavaScriptSupport jss_, String input) {
  JSONObject config = new JSONObject();
  config = new JSONObject();
  config.put("arg", input);
  jss_.require("addInput").invoke("publicFunc").with(config);/* publicFunc never gets executed when called from onAjaxEvent but works fine when called from afterRender */
}
void afterRender() {
  JSONObject config = new JSONObject();
  javaScriptSupport.require("mainScript").with(config);
  addInput(javaScriptSupport, "this call works fine");
}

addCallback-construct 是基于Tapestry 5.4 多次调用 jquery

我在 java1.7 上使用 Tapestry5-jquery 4.0.0 和 Tapestry5.4.0。该问题似乎特定于 Tapestry 5.4.0,因为 addInput 是一个简单的 addScript("alert('it works!')"); 工作得很好...

感谢您的反馈意见!

4

0 回答 0