【问题标题】:Xpages - Repeat control with SSJSXpages - 使用 SSJS 进行重复控制
【发布时间】:2018-01-09 14:04:01
【问题描述】:

我正在构建一个历史跟踪器,它可以继续使用非 xpage 应用程序中的遗留代码。对于 xpage 应用程序,我只需调用以下函数。这工作正常:

function AddObjectivesHistoryItem(doc, dt, action, username){

var ArrDocHistory:array = doc.getItemValueArray("History");

if(ArrDocHistory.length < 1){

// This should always return an object as it is created when an objectives 
document is first 
// created but do this check to be safe and create an array if for some 
reason it doesnt exist
ArrDocHistory = [dt+"|"+action+"|"+username];
}else{
// append new value to the array
ArrDocHistory.push(dt+"|"+action+"|"+username);
}
return ArrDocHistory;
}

我遇到的问题是拆分和显示 3 种数据类型。我有 3 个计算字段,即重复控件内的表中的日期、用户名和状态,代码,包括下面的第一列和计算字段,这应该是每个多值的第一个管道分隔符之前的所有值。:

<table class="table table-hover">
 <thead>
<tr>
  <th>Date</th>
  <th>Action</th>
  <th>Username</th>
</tr>
</thead>
</table>
                <table class="table table-hover">
      <xp:repeat value="#{document1.History}" var="row">
<tbody>
<tr>
  <td>
            <xp:text escape="true" id="computedField1">
                <xp:this.value><![CDATA[#{javascript:var ArrDocHistory:array = document1.getItemValueArray("History");
print ("LEN: " + ArrDocHistory.length);
var test:array = new Array();
for (i=0; i<ArrDocHistory.length; i++){
var split = ArrDocHistory[i].split("|");
test.push(split[0]);
//return split[i]
}
return test}]]></xp:this.value> 
            </xp:text></td>

但是,这显示的是所有值,在一行中,用逗号分隔。例如,“value1,value2,value3”正如我所料,需要,并且似乎无法让每个值在新行中单独显示。例如:

值1

值2

值3

我知道我在做一些愚蠢的事情,但目前正遭受隧道视力的困扰,因此非常感谢任何指点。

【问题讨论】:

  • 看起来您在重复中循环历史字段。跳过它并在重复时使用行变量
  • 干杯托马斯..

标签: xpages xpages-ssjs


【解决方案1】:

您将 Test 返回到单个计算域。更改您的重复以返回数组'test',(它像您一样获取值,而不是将其拆分为您拥有的数组)。然后计算字段返回测试元素之一。

在计算域之后放置一个分页符,以便以您想要的方式查看它。

【讨论】:

  • 嗨,Brian,我的重复代码现在与计算字段相同,因此应该返回测试。然后,对于计算字段,我返回 row[0] 但这返回 undefined?
  • 忽略这个,我显然不需要[0]!似乎按预期工作,谢谢!
猜你喜欢
  • 1970-01-01
  • 2020-10-27
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多