日期:2014-05-17  浏览次数:20833 次

怎么把jsp里的list赋值给js里的一个键值对数组
request里有一货币对象的list
List currList = query.getResultList();
request.setAttribute("currList", currList);
我想在jsp里取出各货币对象的币种和精度,保存成currHashMap["CNY"]=2这种形式
怎么做

<script type="text/javascript">
var currHashMap=new Array();
</script>

<c:forEach items="${currList}" var="currvo">
String code=${currvo.curr_code};
String pre=${currvo.currPrecision};
</c:forEach>

对js jsp 标签 不熟,上面怎么改,或新写个。

------解决方案--------------------
<s:iterator id="c" value="%{categories}" status="stuts">
parentId='${c.parent.categoryId}';
if(parentId.length==0)
parentId=0;
d.add(${c.categoryId},parentId,'${c.name}','javascript:openCategory(${c.categoryId})');
</s:iterator>


categories 是集合。
------解决方案--------------------
JScript code

<script type="text/javascript">
var currHashMap=new Array();
<%
<c:forEach items="${currList}" var="currvo">
String code=${currvo.curr_code};
String pre=${currvo.currPrecision};
%>
currHashMap[<%=code%>]=<%=pre%>;
<%
</c:forEach>
%>
</script>

------解决方案--------------------
<c:forEach items="${currList}" var="currvo">
<c:out values="${currvo.curr_code"></c:out>
<c:out values="${currvo.currPrecision"></c:out>

</c:forEach>

这样就可以了
------解决方案--------------------
探讨
<s:iterator id="c" value="%{categories}" status="stuts">
parentId='${c.parent.categoryId}';
if(parentId.length==0)
parentId=0;
d.add(${c.categoryId},parentId,'${c.name}','javascript:openCategory($……