问题
I have been learning Xpages programming. We are currently using domino 8.5.2. I am gaining familiarity with the display/input controls and I have had some success using them to display information from backend domino documents, views, scoped variables that are not an array. What I have not been able to discover is how to display the elements of a scoped variable array that is created dynamically.
For instance: I create an array with a number of elements. I can print the elements to the domino log with the following code:
for (var i=0; i<array.length; i++) {
print(array[i])
}
What do I use to display the individual elements on webpage? I apologize if the answer if obvious. I did find one posting about displaying a 2 dimensional array - but was unable to interpret the answer.
Thanks for any guidance.
---Lisa&
回答1:
Use a repeat control and show elements within repeat in a computed field:
<xp:this.beforePageLoad><![CDATA[#{javascript:
var myTest = [];
for (var i=0; i<9; i++) {
myTest[i] = i;
}
viewScope.myTest = myTest;
}]]></xp:this.beforePageLoad>
<xp:repeat
id="repeat1"
rows="30"
var="row"
value="#{viewScope.myTest}">
<xp:text
escape="true"
id="computedField1"
value="#{javascript:row.toString()}">
</xp:text>
<br />
</xp:repeat>
The array is in viewScope.myTest in this example.
回答2:
A very quick way to display the content of an array is using the join function. No repeat required but the display is limited.
<xp:this.beforePageLoad><![CDATA[#{javascript:
var arrTest= ["a","b","c","d"];
viewScope.myTest = myTest;
}]]></xp:this.beforePageLoad>
<xp:text id="testField"
value="#{javascript:viewScope.arrTest.join('; ')">
</xp:text>
This shows
a; b; c; d
You could add HTML around it to pretty it up, and set the display type of the text field to be HTML whcih gives you the opton to join with HTML eg
value="#{javascript:viewScope.arrTest.join('<br>')"
Not as complete a solution as a repeat control, but good for quick things.
来源:https://stackoverflow.com/questions/31951343/xpages-ssjs-how-to-display-an-array