xPages repeat control with scoped variable as data source

后端 未结 2 1395
无人共我
无人共我 2020-12-21 08:53

I need to build repeat control or (view or data table) that uses scoped variable as data source. And the scoped variable should be an array.. Or even just javaScript array..

相关标签:
2条回答
  • 2020-12-21 09:12

    I understand your question the way that you want to use a two dimensional viewScope variable in your repeat control.

    You can define such a two dimensional array in JavaScript this way:

    viewScope.myTest = 
           [["Val_1_1", "Val_1_2"], ["Val_2_1", "Val_2_2"], ["Val_3_1", "Val_3_2"]];
    

    or similar to your third code snippet:

    viewScope.myTest = [];
    viewScope.myTest.push(["Val_1_1", "Val_1_2"]);
    viewScope.myTest.push(["Val_2_1", "Val_2_2"]);
    viewScope.myTest.push(["Val_3_1", "Val_3_2"]);
    

    The repeat control iterates through the first array level and writes the second level into a variable row:

    <xp:repeat
        id="repeat1"
        rows="30"
        var="row"
        value="#{viewScope.myTest}">
        <xp:text value="#{row[0]}" />
        &#160;
        <xp:text value="#{row[1]}" />
        <br />
    </xp:repeat>
    

    You can access the values with row[0] and row[1].

    This example renders the following output:

    Val_1_1 Val_1_2
    Val_2_1 Val_2_2
    Val_3_1 Val_3_2
    
    0 讨论(0)
  • 2020-12-21 09:14

    It's worth looking at java.util.ArrayList or java.util.HashMap. The first gives a one dimensional object, the second a two-dimensional. You'll probably get better typeahead support. HashMap may seem scary, but it's actually very familiar to you - scoped variables are HashMaps. myMap.keySet() is what to use as the "value" for your repeat, then assuming var="key" you can use myMap.get(key) to get the value.

    If you want to use JavaScript objects, look at the video I did for TLCC's webinar last year of my 2013 IBM Connect session with Mike McGarel "It's Not Herculean...". I do exactly that.

    0 讨论(0)
提交回复
热议问题