import android.util.Log; import android.widget.Toast; import com.taobao.weex.annotation.JSMethod; import com.taobao.weex.bridge.JSCallback; import com.taobao.weex.common.WXModule; import com.taobao.weex.common.WXModuleAnno;
public class MyModule extends WXModule {
@JSMethod(uiThread = false)
public void openWx(String msg,JSCallback callback) {
//JSONObject j=http.getData();;
String str ="[{\"Code\":\"123\",\"Name\":\"陈生\"},{\"Code\":\"12\",\"Name\":\"陈生2\"}]";//http.JSONtoStr();
// JSONObject j=http.getData();
com.alibaba.fastjson.JSONObject js=http.JhttpRequest("http://192.168.1.25:8080/testmybatis/syndata.do?","GET","syntools&currpage=1&pagesize=20&field=EmployeeID,Code,Name&tbl=Employee&keyid=EmployeeID");;//new com.alibaba.fastjson.JSONObject();
// System.out.println("alibaba-OBJ:"+js.getJSONArray("obj").toString());
//js.put("ls",str);
/* try {
j = new JSONObject(str);
}catch (JSONException e) {
e.printStackTrace();
} */
callback.invokeAndKeepAlive(js);
}
}
Application 中注册
public class WeexApplication extends Application {
@Override
public void onCreate() {
super.onCreate();
InitConfig.Builder builder = new InitConfig.Builder();
builder.setImgAdapter(new ImageAdapter());
InitConfig config = builder.build();
WXSDKEngine.initialize(this, config);
try {
//通信方法 myModule是weex调用原生的方法名
WXSDKEngine.registerModule("myModule", MyModule.class);
} catch (WXException e) {
e.printStackTrace();
}
Log.i("Application", "WXSDKEngine.isInitialized: " + WXSDKEngine.isInitialized());
initDebugEnvironment(true, "192.168.1.25"/*"DEBUG_SERVER_HOST"*/);//导入调试
}
private void initDebugEnvironment(boolean enable, String host) {
WXEnvironment.sRemoteDebugMode = enable;
WXEnvironment.sRemoteDebugProxyUrl = "ws://" + host + ":8089/debugProxy/native";
}
}
const res= weex.requireModule('myModule');
res.openWx("给android的模块传送",(event)=>{
//回调后处理
// func.printLog('回调: ' + event);
console.log("回调的值aaaa:"+event);
console.log("回调的值msg:"+event.msg);
console.log("回调的值 obj:"+event.obj);
var a=[];//new Array();
a=event.obj;
for(var i=0;i
console.log("编码:"+a[i].Code);
console.log("名字:"+a[i].Name);
}
console.log("this的值:"+this);
this.lists=a;//JSON.stringify(event.obj);
//Array a=event.obj;
// var array=new Array();
//array=event.obj;
/* for(var i=0;i
console.log("编码:"+array[i].Code);
console.log("名字:"+array[i].Name);
} */
});
}