Xpages SSJS How to display an array?

蹲街弑〆低调 提交于 2020-02-03 10:27:48

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!