XPage - Dojo 过滤选择 - 保存标签和值 [英] XPages - Dojo Filtering Select - save both label and value

查看:33
本文介绍了XPage - Dojo 过滤选择 - 保存标签和值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 XPage 上使用 Dojo 过滤选择控件,并希望在保存 XPage 时同时保存标签和值.我可以将两个值保存到相同或不同的字段吗?

I'm using a Dojo Filtering Select control on an XPage and would like to save both the label and value when the XPage is saved. Is it possible for me to save both values to either the same or separate fields?

推荐答案

您想将文档的字段设置为当前选定值的对应标签.

You'd like to set a document's field to the corresponding label of currently selected value.

下面的代码适用于定义的 xp:selectItem 项目和基于属性、视图、bean 或其他源的所有类型的计算 xp:selectItems 定义.

The code below works for defined xp:selectItem items and all kinds of computed xp:selectItems definitions based on a property, a view, a bean or other source.

服务器端 JavaScript 解决方案

添加以下 SSJS 代码以在 onclick 事件提交按钮:

Add following SSJS code to submit button at onclick event:

<xp:this.action><![CDATA[#{javascript:
            var select = getComponent('djFilteringSelect1'); 
            var list = select.getChildren();
            var value = select.getValue();
            var label = "";
            for (var i = 0; i < list.length && label === ""; i++) { 
                print (i);
                if (typeof list[i] === 'com.ibm.xsp.component.UISelectItemEx') {
                    if (list[i].getItemValue() === value) { 
                        label = list[i].getItemLabel();
                    }
                } else if (typeof list[i] === 'com.ibm.xsp.component.UISelectItemsEx') {
                    items = list[i].getValue();
                    for (var k = 0; k < items.length && label === ""; k++) {
                        if (items[k].getValue() === value) { 
                            label = items[k].getLabel();
                        }                       
                    }
                }
            }
            document1.setValue("label", label)
}]]></xp:this.action>

它遍历所有已定义的Dojo Filtering Select 控件的selectItems,查找选定的值并将相应的标签写入文档的标签"字段.

It runs through all defined selectItems of Dojo Filtering Select control, looks for selected value and writes the corresponding label to document's field "label".

客户端 JavaScript 解决方案

创建一个隐藏的输入字段,它连接到文档的字段标签":

Create a hidden input field which is connected to document's field "label":

<span style="display:none">
    <xp:inputText
        id="fieldLabel"
        value="#{document1.label}">
    </xp:inputText>
</span>

添加以下 CSJS 代码以在 onclick 事件提交按钮:

Add following CSJS code to submit button at onclick event:

<xp:this.script><![CDATA[XSP.getElementById("#{id:fieldLabel}").value =
     dijit.byId('#{id:djFilteringSelect1}').get('displayedValue')]]>
</xp:this.script>

它将输入字段设置为当前选定值的标签,并从那里写入文档的字段标签".

It sets the input field to the label of currently selected value and from there it gets written to document's field "label".

这篇关于XPage - Dojo 过滤选择 - 保存标签和值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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