带有组合框控件的optgroup

时间:2012-06-27 12:37:44

标签: xpages

是否可以通过native或ExtLib Combo框控件在select中呈现<optgroup>个标签?

我想使用本机解决方案,因此getComponent()或验证器将起作用。我认为这会使用jQuery / dojo取消内联html的资格。

2 个答案:

答案 0 :(得分:1)

<optGroup>标签喷气机似乎没有原生支持。然而,与不合格jQuery / dojo的假设相反,这似乎是解决方案。其中getComponent(),getValue(),setValue()等仍在工作。

您需要的每个<optGroup>唯一需要做的就是添加<xp:selectItem itemLabel="With your optGroup label" itemValue"optGroup1"></xp:selectItem>。当使用多个<optGroups>'s时,itemValue需要增加1.我在下面粘贴了一个示例,希望这会有所帮助。

<xp:this.resources>
    <xp:script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js" clientSide="true"></xp:script>
</xp:this.resources>
...
<xp:comboBox id="comboBox1" styleClass="optGroup">
    <xp:selectItem itemLabel="Swedish Cars" itemValue="optGroup1"></xp:selectItem>
    <xp:selectItem itemLabel="Volvo" itemValue="volvo"></xp:selectItem>
    <xp:selectItem itemLabel="Saab" itemValue="saab"></xp:selectItem>
    <xp:selectItem itemLabel="German Cars" itemValue="optGroup2"></xp:selectItem>
    <xp:selectItem itemLabel="Mercedes" itemValue="mercedes"></xp:selectItem>
    <xp:selectItem itemLabel="Audi" itemValue="audi"></xp:selectItem>
</xp:comboBox>

<xp:scriptBlock id="scriptBlock1">
    <xp:this.value><![CDATA[
    //Iterate across the <option>'s for which the itemValues begin with "optGroup".
    $('.optGroup option[value^="optGroup"]').each(function(index, node) {
        //Use the actual itemValue ("optGroup1") to get all its siblings until the next
        //<option> is found with (again) an itemValue of "optGroup" (i.e. "optGroup2").
        $('.optGroup option[value="' + node.value + '"]').
            //No harm for last iteration: .nextAll() will be used if the selector is
            //not matched or is not supplied (in this example "optGroup3" won't get a match).
            nextUntil('.optGroup option[value="optGroup' + (index + 2) + '"]').
            //Wrap them in a <optGroup> tag and give it its label (itemLabel).
            wrapAll('<optGroup label="' + node.text + '"></optGroup>');
        //Remove the initial <option> since we no longer need it.
        $(this).remove();   
    });
    ]]></xp:this.value>
</xp:scriptBlock>

<xp:button value="Submit" id="button1">
    <xp:eventHandler event="onclick" submit="true"
        refreshMode="complete">
        <xp:this.action><![CDATA[#{javascript:
        print("Submitting: " + getComponent("comboBox1").getValue() );
        }]]></xp:this.action>
    </xp:eventHandler>
</xp:button>

答案 1 :(得分:1)

我找到了这个问题的答案。 Domino Designer中组合框的计算值可以返回字符串向量/数组,通常作为@DbLookup或@DbColumn的返回值。在进行实验时,我发现您可以为选择项返回本机组件,包括组(继承自select项)。 以下片段将构建我想要的东西:分组项目的层次结构。

<?xml version="1.0" encoding="UTF-8"?>
<xp:view xmlns:xp="http://www.ibm.com/xsp/core">
    <xp:comboBox id="comboBox1" value="#{viewScope.combo}">
        <xp:selectItems>
            <xp:this.value><![CDATA[${javascript:var itms = new javax.faces.model.SelectItem[2];
var itm = null;
itm = new javax.faces.model.SelectItem();
itm.setLabel("label1");
itms[0] = itm;
itm = new javax.faces.model.SelectItem();
itm.setLabel("label2");
itms[1] = itm;

var g = new javax.faces.model.SelectItemGroup();
g.setLabel("Group");
g.setSelectItems(itms);
g
}]]></xp:this.value>
        </xp:selectItems>
    </xp:comboBox>
</xp:view>

样品:

Combo sample

基于此示例,您可以组合许多数据源来构建计算的<optgroup>组合,包括支持bean或范围变量。