1

I've setup a repeater and am reading the value from the multivalue field using GetItemValueArray. This returns the array and If I use a listbox it displays. I want to cross reference some other data with it though so I need to use a repeater. But I'm not sure how to have the repeater use an index that increments for each row. The code below "return rowdata[i]" doesn't recognize i.

<xp:repeat id="repeat1" var="rowdata" rows="30">
    <xp:this.value>
       <![CDATA[#{javascript:var myArray:Array = myDataSource.getItemValueArray("MyMultiValueFld")}]]>
    </xp:this.value>
    <xp:label id="lbl">
        <xp:this.value><![CDATA[#{javascript:return rowdata[i];}]]></xp:this.value>
    </xp:label>
</xp:repeat>
L.Pursell
  • 78
  • 5

6 Answers6

5

rowdata is not a reference to the myArray value as a whole, but the iterated entry in myArray. In other words... you already have what you need.

<xp:label value="#{rowdata}" />
Chris Toohey
  • 146
  • 5
  • I've tried that what shops up in the repeater label is "myArray" not what is actually in the array. So if my array contains 3 values "Name1", "Name2", "Name3" all I see is "MyArray" not the list of names. – L.Pursell Aug 11 '14 at 18:16
1

Maybe you can simplify your code by naming using just the "rowdata" as value for your text item. You then should only change the repeat source to

myDataSource.getItemValue("myValueFld")

as this returns always an array of data. It's just depending on the datatype that this item stores, so you might have to convert in the text control.

Oliver Busse
  • 3,375
  • 1
  • 16
  • 26
1

Hi there your code has another issue, you do not have any return statement in this line:

<xp:this.value>
   <![CDATA[#{javascript:var myArray:Array = myDataSource.getItemValueArray("MyMultiValueFld")}]>
</xp:this.value>

so the code does not return your myArray it only Returns the name of it as a string wich gets repeatet one time. Use this a valueBinding:

value="#{myDataSource.MyMultiValueFld}"

or add a return:

    <xp:this.value>
       <![CDATA[#{javascript:var myArray:Array = myDataSource.getItemValueArray("MyMultiValueFld");
 return myArray;}]>
    </xp:this.value>

Then you should be able to use Chris Tooheys Answer:

<xp:label value="#{rowdata}"/>
Michael Saiz
  • 1,640
  • 12
  • 20
0

Use the indexVar property of the repeat control to setup a var containing the index.

Per Henrik Lausten
  • 21,331
  • 3
  • 29
  • 76
0

Got it. The final piece of code is that I did have to create an indexVar="I" in my repeat1 tag but then I also had to change my label to a computed field. The final piece of code looks like:

<xp:table>
    <xp:repeat id="repeat1" var="rowdata" rows="30" indexVar="i" first="0">
        <xp:this.value><![CDATA[#{javascript:myDataSource.getItemValueArray("myMultivalueFld");}]]>
        </xp:this.value>
        <xp:tr><xp:td>
            <xp:text escape="true" id="computedField1">
                <xp:this.value><![CDATA[#{javascript:var repeat1:com.ibm.xsp.component.xp.XspDataIterator = getComponent("repeat1");
                      repeat1.getValue()[i];}]]></xp:this.value>
            </xp:text>
        </xp:td>
       </xp:tr>
    </xp:repeat>
</xp:table>

don't think I could have gotten it without the tidbit on the indexVar. Thanks

L.Pursell
  • 78
  • 5
  • 5
    I'm glad you have this working BUT this solution is overly complex and should NOT be thought of as best practice by anyone reading this answer. The Toohey and Busse answers are the better way of doing and should have worked fine for you. Respectfully you likely had a bug somewhere when you said you tested and it brought back "myArray". – David Leedy Aug 11 '14 at 19:44
  • I agree with @DavidLeedy: the code is overcomplicated, lots of SSJS where you can have just two simple ELs: #{myDataSource.myMultivalueFld} and #{rowdata}... – Frantisek Kossuth Aug 12 '14 at 14:32
0

You can trim that code further. If all you need is the values, you don't need the indexvar and you don't need to reference the repeat as an XspDataIterator. Just use the rowdata as a variable.

<xp:table>
<xp:repeat id="repeat1" var="rowdata" rows="30">
    <xp:this.value><![CDATA[#{javascript:myDataSource.getItemValueArray("myMultivalueFld");}]]>
    </xp:this.value>
    <xp:tr><xp:td>
        <xp:text escape="true" id="computedField1">
            <xp:this.value><![CDATA[#{javascript:rowdata;}]]></xp:this.value>
        </xp:text>
    </xp:td>
   </xp:tr>
</xp:repeat>

Each value in the multi-value field is a "row" as referenced by rowdata. Similarly, if the data source were a view, each row would reference a document object. Don't dispose of the framework available to you by accessing the repeat as a component from inside the component itself.

David Navarre
  • 1,022
  • 10
  • 27