2维java数组转换成javascript函数

时间:2014-01-16 06:54:00

标签: gwt

如何将2维java数组传递给javascript函数?混合型数组。

String[][] str={
            {"Year", "Austria", "Bulgaria", "Denmark", "Greece"},
            {"2003",  "1336060",    "400361",    "1001582",   "997974"},
            {"2004",  "1538156",    "366849",    "1119450",   "941795"},
            {"2005",  "1576579",    "440514",    "993360",    "930593"},
                    {"2006",  "1600652",    "434552",    "1004163",   "897127"},
                    {"2007",  "1968113",    "393032",    "979198",    "1080887"},
                    {"2008",  "1901067",    "517206",    "916965",    "1056036"}


private native void createChart(String[][] str) 

1 个答案:

答案 0 :(得分:0)

我会把它发布在一个commet中,但我不认为它真的可读。在GWT中有你可以传递给JSNI的JsArrayMixed。这里的例子如下:

JsArrayMixed bigArray= JavaScriptObject.createArray().cast();
for(int i=1;i<yourNumberOfRows;i++) { 
    JsArrayMixed row= JavaScriptObject.createArray().cast(); 
    for(int j=0;j<yourDataRowCount;j++) { 
        row.push(str[i][j]); 
    } 
    bigArray.push(row); 
}

希望这有帮助, 的Ovi