问题
I have a Combo Box and I would like to have the possibility to add new values in the Combo Box using a button and an Input Field. I tried with:
var value = getComponent("input").getValue();
getComponent("combobox").setValue(value);
but it is not working.
Thank you,
Florin
回答1:
Use a viewScope e.g. viewScope.selectItems
variable.
- Use this viewScope as the selectItems list.
- Add the initial values to it.
- Later, add a additional new item to this viewScope and then it will appear in combobox's selection item list.
This is a working example:
<xp:comboBox
id="comboBox1"
value="#{sessionScope.test}">
<xp:selectItems>
<xp:this.value><![CDATA[#{javascript:
if (!viewScope.selectItems) {
viewScope.selectItems = ["your","initial","values"];
}
return viewScope.selectItems;}]]></xp:this.value>
</xp:selectItems>
</xp:comboBox>
<xp:inputText
id="inputText1"
value="#{viewScope.newItem}">
</xp:inputText>
<xp:button
value="Add to selectItems"
id="button1">
<xp:eventHandler
event="onclick"
submit="true"
refreshMode="complete">
<xp:this.action><![CDATA[#{javascript:
viewScope.selectItems.add(viewScope.newItem);
viewScope.newItem = "";
}]]></xp:this.action>
</xp:eventHandler>
</xp:button>
来源:https://stackoverflow.com/questions/25717857/xpages-add-values-into-combo-box