如何将数组从struts2散列到大小不确定的javascript数组?

如何将数组从struts2散列到大小不确定的javascript数组?,javascript,for-loop,struts2,hashtable,Javascript,For Loop,Struts2,Hashtable,我正在尝试根据用户在下拉框中选择的内容更新图像(无需单击“提交”或其他任何操作),我已使其正常工作,但有一点除外—它对可用选项的数量有一个上限: var hash = new Array(); hash['<s:property value="itemLists[1][0].id"/>']=0; hash['<s:property value="itemLists[1][1].id"/>']=1; hash['<s:property value="itemLists

我正在尝试根据用户在下拉框中选择的内容更新图像(无需单击“提交”或其他任何操作),我已使其正常工作,但有一点除外—它对可用选项的数量有一个上限:

var hash = new Array();
hash['<s:property value="itemLists[1][0].id"/>']=0;
hash['<s:property value="itemLists[1][1].id"/>']=1;
hash['<s:property value="itemLists[1][2].id"/>']=2;
hash['<s:property value="itemLists[1][3].id"/>']=3;
hash['<s:property value="itemLists[1][4].id"/>']=4;
hash['<s:property value="itemLists[1][5].id"/>']=5;
hash['<s:property value="itemLists[1][6].id"/>']=6;
hash['<s:property value="itemLists[1][7].id"/>']=7;
var item= new Array();
item[0] = '<s:property value="itemLists[1][0].image"/>';
item[1] = '<s:property value="itemLists[1][1].image"/>';
item[2] = '<s:property value="itemLists[1][2].image"/>';
item[3] = '<s:property value="itemLists[1][3].image"/>';
item[4] = '<s:property value="itemLists[1][4].image"/>';
item[5] = '<s:property value="itemLists[1][5].image"/>';
item[6] = '<s:property value="itemLists[1][6].image"/>';
item[7] = '<s:property value="itemLists[1][7].image"/>';
var hash=new Array();
散列['']=0;
散列['']=1;
散列['']=2;
散列['']=3;
散列['']=4;
散列['']=5;
散列['']=6;
散列['']=7;
var item=新数组();
项目[0]='';
第[1]项=“”;
第[2]项='';
第[3]项='';
第[4]项=“”;
第[5]项='';
第[6]项='';
第[7]项=“”;
这显然是太具体了,我想知道是否有一种方法可以说,为列表中的每一项创建一个for循环。当页面第一次加载时,Struts2-<代码> '/COD>会出现问题,并且“字符串”不能在中间用一个迭代器变量分成两部分。有没有一种方法可以在Javascript函数中使用带有struts2数组的for循环?

对于上面的一个循环,大约(读取:未测试):

var items = [];
<s:iterator list="itemLists[1]" var="item" varStatus="stat">
  items.push('<s:property value="#item[#stat.index].image"/>');
</s:iterator>
JSP标记所做的全部工作就是创建要发送到客户端的文本

文本是什么并不重要——没有理由不能是JavaScript源代码


您还可以将数据公开为JSON/straight JS,从而避免很多繁忙的工作。

谢谢!最后你关于记住我实际做的事情的评论让我朝着正确的方向思考,我找到了一个根本不需要使用数组的解决方案。
var items = [];
<s:iterator list="itemLists[1]" var="item" varStatus="stat">
  items.push({
    id:    '<s:property value="#item[#stat.index].id"/>',
    image: '<s:property value="#item[#stat.index].image"/>
  });
</s:iterator>