2012-11-08 48 views
0

任何人都可以請我解釋一下invoke方法中的參數如何正確使用。BlackBerry的對象調用(Object thiz,Object [] args)方法的用法

browserField.extendScriptEngine("interesting.test", new ScriptableFunction() { 

    public Object invoke(Object thiz, Object[] args) throws Exception { 

     Dialog.alert("Done"); 

     return super.invoke(thiz, args); 
    } 
}); 

我在HTML文件中調用上面的方法如下。

<button type="button" onclick="interesting.test()">Display Alert</button> 

當我使用以下代碼

System.out.println("# thiz : " + thiz.toString()); 

結果是

[0.0] # thiz : net.[email protected]a2f32d2a 

,當我使用此代碼

System.out.println("# args : " + args.length); 

結果是

[0.0] # args : 0 

在控制檯上打印。

我已經在invoke方法中使用了這兩個System.out方法。另外我也參考了API文檔,並且仍然無法理解如何將值傳遞給這兩個參數並檢索它們。

回答

0

你可以試試這個,它爲我工作

  try{ 

       browserField.extendScriptEngine("interesting.test", new ScriptableFunction() { 

       public Object invoke(Object thiz, static Object[] args) throws Exception { 

        Dialog.alert(String.valueOf(args[0]).toString()); 

       } 
       }); 

      } catch(Exception e){ 
       // 
      } 

,然後從HTML做到這一點

<button type="button" onclick="interesting.test('cool')">Display Alert</button> 

,因爲這些參數是簡單的數組對象可以指具有一個以上的參數同時出於靈活性目的,它的類似於在javascript中使用的參數。所以試試吧......

相關問題