Im using struts2 tags for my application. I need to change the value randomly from script to s:set tag and populate into the javascript array. If i add dynamically means i get the output as 2012 - diff + 1 but my expected output as 2011 . How can i achieve this, my code is
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>
i need my final array value should be link
['x', 'Cats','Dogs'],
['2008', 10, null],
['2009', 20, null],
['2010', null, null],
['2011', null, 23],
['2012', null, 34]
You can use the eval() method in JavaScript. So, if you can generate something like
var incyear = eval('<s:property value="year"/> - diff + 1');
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments