日期:2014-05-16  浏览次数:20392 次

在JSP页面用JS处理从服务器返回的LIST集合
注:需要 struts2 框架,没有就不行
附件中部分代码:
<script type="text/javascript">
function test(){
var a = "<%= request.getAttribute("parameterValue") %>";
var list = "<%= request.getAttribute("userData") %>";
var userArray = new Array();
var uid;
var uname;
var uaddress;
var index;
<s:iterator value="#request.userData" id="item" status="st">
var children = new Array();
   uid = "<s:property value='uid'/>";
   uname = "<s:property value='uname'/>"; //因为是字符串类型,所以要用双引号或单引号,如果语法有错,那么接下来的JS失效
   uaddress = "<s:property value='uaddress'/>";
  
   children[0] = uid;
   children[1] = uname;
   children[2] = uaddress;
  
   userArray[<s:property value="#st.index"/>] = children;
   </s:iterator>
   for(var i=0; i<userArray.length; i++){
   var tempArray = userArray[i];
   for(var j=0; j<tempArray.length; j++){
   alert(tempArray[j]);
   }
   }
document.getElementById("dId").innerHTML = "abc";
}
</script>