Search code examples
xpagescomputed-field

XPages Create Links from Array in Computed Field


I put a computed filed in a XPages and then i created value via this code below. Every line has its own link but before i complete this code i am trying to learn how to remove the comma at the beginning of line. There must be another way to do this. Should i use one of other design elements like repeat control?

<xp:text escape="false" id="computedField1" style="font-size:8pt">
  <xp:this.value>
  <![CDATA[#{javascript:{ var links = ["A1","A2","A3","","A444",""];
for (i=0;i<arr1.length;i++) {
    var strText = arr1[i];
    if (strText=="") {
      strText = "There is no value";
    }
    links[i] =  "<a href="+ arr1[i] + "target=\"_blank\">"+strText+"</a><br>";
  }
  return links;}]]></xp:this.value>
</xp:text>


How to remove COMMA in array

Any suggestion is appreciated,
Cumhur Ata


Solution

  • Cumhur, as Paul pointed, a repeat loop is the best for such a purpose.

    For this specific case, you return an array as a value. Imploding the array to a string will solve your issue.

    return @Implode(links,"\n");
    

    Also, instead of adding <br> on every elements, you can use it as a separator.

    return @Implode(links,"<br/>");