【发布时间】:2018-03-15 19:11:06
【问题描述】:
我在通过 JavaScript 文件填充的 xPage 上有一个组合框。
这个 xPage 还有一个 postNewDocument 事件,它调用一个 LotusScript 代理,该代理从内存中的文档中预填充 xPage 上的大部分字段,它适用于除此类字段之外的所有字段,因为组合框的值是'在为该字段调用 JavaScript 文件之前不会填充。
我能看到从内存文档中选择组合框条目的最有效方法是将文档中的值放入文本字段,然后从该字段中读取它。以下是组合框的 Values 字段中的内容:
var rArray = getItemOptions();
var prevCountry = getComponent("Org_Country").getValue();
var opt;
if ((prevCountry != "") && (prevCountry != null)){
for (var i=0; i < rArray.length; i++) {
rArray[i];
opt = rArray[i];
if (opt.contains(prevCountry)) {
rArray.selectedIndex = i;
}
}
}
return rArray;
下面是一些源代码的样子:
<option value="1">Afghanistan</option>
<option value="2">Albania</option>
<option value="3">Algeria</option>
<option value="4">American Samoa</option>
我认为我需要做的是设置 selected="selected" 但 rArray 中没有“选项”。我尝试了其他变体,例如 rArray[i].selected = true 和 rArray[i].selected = "selected",它们不会产生错误,而只会产生整个组合框。
我想选择之前选择的组合框项目,但将其保留在组合框中的相同位置并允许用户更改他们的选择。
这是我的组合框的标记:
<xp:comboBox id="Country" value="#{document1.Country}" styleClass="form-control">
<xp:selectItems>
<xp:this.value><![CDATA[#{javascript:return getItemOptions();}]]> </xp:this.value>
</xp:selectItems>
<xp:eventHandler event="onchange" submit="true" refreshMode="partial"
disableValidators="true"
refreshId="Province">
<xp:this.action><![CDATA[#{javascript:var selected = getComponent("Country").value;
viewScope.put("countrySelected", selected);}]]></xp:this.action>
<xp:this.onComplete><![CDATA[$("form").formValidation("addField", "#{id:Province}");
]]></xp:this.onComplete>
</xp:eventHandler>
</xp:comboBox>
我现在开始将这段代码放在 onClientLoad 事件中,但我还没有让它工作。
这些国家/地区的数字来自我在其他地方获得的数据库,但我可以更改它们。
【问题讨论】:
-
组合框的标记是什么样的? xp 一个。通常您只需将值绑定到支持文档。一个技巧:使用文档服务器端的一个值预先填充下拉列表。附带说明:不要使用国家/地区的数字。使用 iso 代码
-
我已经添加了上面的标记。
标签: javascript arrays combobox xpages xpages-ssjs