Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
2.1k views
in Technique[技术] by (71.8m points)

arrays - xPages repeat control with scoped variable as data source

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..

scoped variable:

viewScope.MY_TEST = new Array();
viewScope.MY_TEST.push("Test1");
viewScope.MY_TEST.push("Test2");

or array:

var my_arr = new Array();
my_arr.push("Test1");
my_arr.push("Test2");

or even an object/two dimensional array:

viewScope.MY_TEST = [];
viewScope.MY_TEST .push([value1, value2]);

so repeat control should contain e.g. two computed fields one is bind to value1, another to value2...

Or give me an example of just one dimensional array..

Thank you

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...