我为我的应用程序使用 struts2 标签。我需要将值从 script 随机更改为 s:set 标记并填充到 javascript 数组中。如果我动态添加意味着我得到的输出为2012 - diff + 1但我的预期输出为2011。我怎么能做到这一点,我的代码是
var threeDatas = [];
var prevyear = [];
var diff;
var flagthree = false;
<% int j = 0;%>
<s:iterator value="testlist">
prevyear.push(<s:property value="year"/>);
if (<%= j - 1%> !== -1) {
if (prevyear[<%= j - 1%>] !== prevyear[<%= j%>] - 1) {
diff = prevyear[<%= j%>] - prevyear[<%= j - 1%>];
}
if (diff > 1) {
for (inc = 1; inc < diff; inc++) {
<s:set var="incyear"> <s:property value="year"/> - diff+1</s:set>
threeDatas.push(['<s:property value="#incyear"/>', null, null]);
}
flagthree = true;
diff = 0;
}
<% j++;%>
</s:iterator>
我需要我的最终数组值应该是链接
['x', 'Cats','Dogs'],
['2008', 10, null],
['2009', 20, null],
['2010', null, null],
['2011', null, 23],
['2012', null, 34]