BaasServer 定义要求 返回值必须是JSONObject 类型的,就相当于map格式,存储键值对,如果想返回更加复杂的类型,也是把这个复杂的值存储在JSONObject 对象中
比如返回一个list集合,在js端接受参数相当于数操作js数组
public static JSONObject service(JSONObject params, ActionContext context) throws JsonGenerationException, JsonMappingException, IOException, WxErrorException{ JSONObject map = new JSONObject(); List<JSONObject> list = new ArrayList<JSONObject>(); JSONObject map1 = new JSONObject(); map1.put("test1","test1"); map1.put("test2","test2"); list.add(map1); map.put("test",list); return map; }
Baas.sendRequest({ "url" : "/baas/请求", "action" : "baasAction", "async" : false "success" : function(data) { debugger; var arr = data.test; for(var i=0;i<arr.length;i++){ alert(arr[i].test1); alert(arr[i].test2); } } });
评一波