1

我为 phonegap 创建了一个简单的插件,但我想将对象作为参数而不是 string 传递,下面是我的代码结构...

BackGroundService.java  

public class BackGroundService extends Plugin {
   public PluginResult execute(String arg0, JSONArray args, String arg2) {  //How can i pass object instead or String       
   }
}

worker.js
var worker = function(name, win, fail) {   
  PhoneGap.exec(win, win, "BackGroundService", "worker", [name]);
}

PhoneGap.addConstructor(function() {
  navigator.app.addService('BackGroundService','com.service.app.BackGroundService');

})  

从 html 调用

worker("football", win);   //Pass object instead of football        

var win = function(d) {
     alert("success");      
} 
4

1 回答 1

0

将对象解压缩成字符串数组?

假设您正在传递一个名为“Sport”的对象,该对象具有以下属性:

.name: "足球" .ball: "round" .periods: 2 .periodTiming: 45

您可以将此对象解压缩为 ["Football", "round", 2, 45],然后修改 Java 代码以获取每个参数:

    String name = args.getString(0);
    String ball = args.getString(1);
    int periods = args.getInt(2);
    int timing = args.getInt(3);

高温高压

于 2012-05-18T12:33:10.140 回答