是否有可能通過本地或ExtLib組合框控件選擇<optgroup>
選擇標籤?optgroup與組合框控件
我想使用原生解決方案,所以getComponent()或驗證器將工作。我認爲這不符合jQuery/dojo的內聯html。
是否有可能通過本地或ExtLib組合框控件選擇<optgroup>
選擇標籤?optgroup與組合框控件
我想使用原生解決方案,所以getComponent()或驗證器將工作。我認爲這不符合jQuery/dojo的內聯html。
我已經找到了我的問題的答案。 Domino Designer中組合框的計算值可以返回字符串矢量/數組,通常作爲@DbLookup或@DbColumn的返回值。在做實驗的過程中,我發現你可以爲選擇的項目返回本地組件,包括組(從選擇項繼承)。 以下片段將構建我想要的內容:項目的分組層次結構。
<?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>
樣品:
基於這個例子中,你可以將多個數據源來構建計算<optgroup>
連擊,包括支持豆類或範圍變量。
似乎並不支持<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>
感謝您的回答,但我儘量避免客戶端腳本攻擊,直到需要。我不使用JQuery。 –