javascript中没有list,只有array。回调也不可能是list,只能是json数组
只有在action中把list转为json,在回调中$.each;
<script>var arr = [ "one","two","three","four","five" ];var obj = { one: 1,two: 2,three: 3,four: 4,five: 5 };jQuery.each( arr,function( i,val ) {$( "#" + val ).text( "Mine is " + val + "." );// Will stop running after "three"return ( val !== "three" );});jQuery.each( obj,val ) {$( "#" + i ).append( document.createTextNode( " - " + val ) );});</script>
function toCommentList()
{
//获取评论列表
$.ajax({
url: "$!base/private/work/cms_info_comment/ajaxCommentList.jhtml",
cache: false,
dataType: "json",//指定了dataType 为json 则不需要再回调中调用$.parseJSON(data);
data: {
"infoId": "$!{infoId}"
},
success: function(data){
var d = $.parseJSON(data);//不需要
console.info(d);
}
});
}
//java 中 List 转 jsonArrary:
JSONArray jsonArray = JSONArray.fromObject(commentList);
System.out.println(jsonArray);
//指定了datatype 为 json ,则 不需要 var d = $.parseJSON(data);//不需要
原文链接:https://www.f2er.com/ajax/161612.html