问题
I want to get the index of an repeat in CSJS. I tried to get the repeatID and then get the value, but it is not working.
var r="view:_id1:repeat1:"
var val=document.getElementById(r).value.toString();
回答1:
Create a computed text like this:
<xp:text
escape="true"
id="computedFieldIndexVar"
tagName="input">
<xp:this.attrs>
<xp:attr
name="type"
value="hidden">
</xp:attr>
<xp:attr
name="value"
value="#{javascript:var rp:com.ibm.xsp.component.xp.XspDataIterator = getComponent('repeat1');rp.getRowCount()}">
</xp:attr>
</xp:this.attrs>
</xp:text>
You can then access the field in CSJS:
var r="view:_id1:computedFieldIndexVar"
var val=document.getElementById(r).value
The repeat control has the id repeat1.
来源:https://stackoverflow.com/questions/25805075/xpages-get-index-of-repeat-in-csjs