2012-03-12 60 views
1

我对gwt相对较新,并且使用JsArrayInteger时遇到问题。这是我的代码:谷歌gwt JsArrayInteger(JavaScriptObject)通过JSNI使用

package com.google.gwt.sample.stockwatcher.client;  
    public class StockWatcher implements EntryPoint { 
     JsArrayInteger a; 
     public void onModuleLoad() { 
      a = (JsArrayInteger) JsArrayInteger.createArray(); 
      a.push(1); 
      a.push(2); 
      a.push(4); 
      a.push(5); 
      test(); 
     } 
     public static native void test() /*-{ 
      var p = [1,2,3,4,5,6]; 
      var q = [email protected]::a; 
      alert(q); 
      alert(p); 
     }-*/; 
    } 

结果 '未定义' 和[1,2,3,4,5,6]而非[1,2,3,4,5]和[1,2 ,3,4,5,6]。我想使用字段a并在该数组上工作(将它传递给第三方库)。

教程http://code.google.com/webtoolkit/doc/latest/DevGuideCodingBasicsJSNI.html没有解释如何使用默认JavaScriptObjetcs。有人发现错误吗?

最好的问候,

迈克尔

回答

1
public static native void test() /*-{ 
     var p = [1,2,3,4,5,6]; 
     var q = [email protected]::a; 
     alert(q); 
     alert(p); 
    }-*/; 

注意,此方法是static,但你指的是this。要么通过一个实例并使用它来代替this,要么将方法更改为不是static

+0

我是多么愚蠢......我虽然是一个复杂的问题......非常感谢! – Michael 2012-03-12 17:09:44

+0

如果只有JSNI代码可以告诉我们'this'没有意义......但这不是JS的工作原理。这就是为什么很多人首先使用GWT。 – 2012-03-12 17:12:01