0

我是一个零 jquery 经验的 GWT 人。对于那个很抱歉。不幸的是,我遇到了一些我必须在我的 GWT 项目中使用的 jquery 功能。

<script type="text/javascript">
$(document).ready(function() {
    zingchart.render({
        'id' : 'g1',
        'width' : 500,
        'height' : 400,
        'dataurl' : 'scatter_minimal.txt'
    });
    });
</script>

<div class="g" id="g1"></div>

凭着我的直觉,我快要相信

$(document).ready( ..)

应该翻译为 GWT's onModuleLoad(){ ....},如果我在 onModuleLoad 中调用该函数,onModuleLoad 将确保 DOM 准备就绪。

但我认为以下内容无效..

private static native void render() /*-{
  function() {
    zingchart.render(
      {
        'id' : 'g1',
        'width' : 500,
        'height' : 400,
        'dataurl' : 'scatter_minimal.txt'
      }
    );
  }
}-*/;

我将如何编码 JSNI 来定义我可以从 GWT 调用的函数?

4

1 回答 1

1

If I understand your question correctly, what you want to do is simply:

private static native void render() /*-{
    zingchart.render(
      {
        'id' : 'g1',
        'width' : 500,
        'height' : 400,
        'dataurl' : 'scatter_minimal.txt'
      }
    );
}-*/;

Then you can call render() from your GWT code. render is the function itself, GWT already defines it for you as a JavaScript function when you use the JSNI syntax.

Background:

Writing function() {...} defines an anonymous function - which is not what you want here (you wouldn't have any way to refer to it, because you don't pass it anywhere). In jQuery, you pass that anonymous function directly to document.ready().

于 2011-08-29T22:12:29.353 回答