increment variable value in spark view engine

83 views
Skip to first unread message

nickname

unread,
May 28, 2012, 6:01:19 PM5/28/12
to Spark View Engine Dev
I try to go through a for each loop and increment value of variable to
name my label with below code

<set i="0"/>
<div each="var x in Model">

<input name='field-${i}' value='${x.Id}'/>

<set i=i+1 />
</div>
but it did not increment the value of 'i' , how can I increment the
value of i in above loop

thanks

Louis DeJardin

unread,
May 28, 2012, 6:38:36 PM5/28/12
to spar...@googlegroups.com
maybe it's not parsing the attribute correctly? try adding quotes around it.

<set i='i+1' />

Another thing to consider is using one of the iterator autovariables to know what the index is. Just add the suffix Index to the iterating var, like:


<div each="var x in Model">
<input name='field-${xIndex}' value='${x.Id}'/>
</div>

Tomek Pluskiewicz

unread,
May 29, 2012, 2:02:28 AM5/29/12
to spar...@googlegroups.com
You can also do i++. Always works for me

<set i="0"/> 
<div each="var x in Model"> 

<input name='field-${i++}' value='${x.Id}'/> 

</div>  

Tomasz

nickname

unread,
May 29, 2012, 6:04:32 PM5/29/12
to spar...@googlegroups.com
Thanks 
Both solutions  works
Reply all
Reply to author
Forward
Message has been deleted
0 new messages