2018-05-23 17:40

----------------------------------------controller
String jsonString = JsonKit.toJson(list);
setAttr("principals", jsonString);
render("chooseUserDataMain.jsp");
----------------------------------------------jsp

var principals = ${principals};

// var jsonObj = $.parseJSON(principals);

var obj = [];
for (var i=0;i var row = {};
row.db_id = principals[i].DB_ID;
row.user_id = principals[i].USER_ID;

obj.push(row);
}



$(document).ready(function(){
layui.use('form', function(){
var form = layui.form();
//各种基于事件的操作,下面会有进一步介绍

});
$('#dg').datagrid('loadData',obj);
});

2018-05-23 17:35

@JFinal 谢谢了.终于出来了.

2018-05-23 16:56

@JFinal
报错了.我搜了一下. 我下面是是不是本来就是json了.
也就是setAttr("principals", list); 本来就传过去json了.
VM5555:1 Uncaught SyntaxError: Unexpected token c in JSON at position 1

"[com.jfinal.plugin.activerecord.Record@d4b28a54 {DB_ID:CD791AD6-C808-145D-FA1F-CECE99187D6A, ID:dfDFSDF, USER_ID:000100128}, com.jfinal.plugin.activerecord.Record@7f2b3095 {DB_ID:CD791AD6-C808-145D-FA1F-CECE99187D6A, ID:FDSFDSfe, USER_ID:000103223}]"



但是 jsp那边应该怎么解析呢
principals.list.length报错.
principals.length会把字符串的长度变成length
var obj = [];
for (var i=0;i var row = {};
row.db_id = principals[i].db_id;
row.user_id = principals[i].user_id;

obj.push(row);
}

2018-05-23 15:08

@JFinal 就是把json的参数传递到jsp

2018-05-23 15:08

@猛虎 就是把json的参数传递到jsp

2018-05-23 14:49

@JFinal 您好.我想render到jsp 然后传递json 有解吗?