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 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);
}