Xpages add values into Combo Box

我只是一个虾纸丫 提交于 2019-12-02 10:37:15

问题


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

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