Xpages将值添加到组合框中 [英] Xpages add values into Combo Box

查看:153
本文介绍了Xpages将值添加到组合框中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个组合框,我想有可能使用按钮和输入字段在组合框中添加新的值。我试过:

  var value = getComponent(input)。getValue 
getComponent(combobox)。setValue(value);

但不起作用。



解决方案

使用viewScope例如 viewScope.selectItems 变量。




  • 将此viewScope用作selectItems列表。

  • 向其添加初始值。

  • 稍后,向此viewScope添加一个新项,然后它将出现在combobox的选择项列表中。



这是一个工作示例:

 < 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 =添加到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>


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

解决方案

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>

这篇关于Xpages将值添加到组合框中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆