带有允许多个实例的自定义属性组的 xPages 自定义控件 [英] xPages Custom Control with Custom Property Group that allows Multiple Instances
问题描述
我创建了一个具有属性定义组的自定义控件.该组已选中允许多个实例".当我将控件放在 xPage 上时,我可以通过 UI 手动向属性添加 2 个项目并设置组的子属性,但我需要弄清楚如何通过循环数组和做一些计算.
I've create a custom control that has a Property Definition Group. The Group has checked to "Allow multiple instances". When I drop the control on an xPage I can through the UI manually add 2 items to the property and set the sub-properties of the group(s) but I need to figure out how to programmatically populate the group by looping through an array and doing some calculations.
推荐答案
我倾向于定义一个名为configuration"的自定义控件属性,并将其设置为对象"(您必须在 vs.从下拉菜单中选择它):
I tend to define a Custom Control Property named "configuration", and set that to be an "object" (you'll have to type that in vs. select it from the dropdown):
现在,您可以传递一个对象作为您的属性:
Now, you can pass an object as your property:
return {
"groups" : {
"groupA" : {
altName : "A Group",
members : ["me", "you", "them"]
},
"groupB" : {
altName : "B Group",
members : ["him", "her", "they"]
}
},
otherOption : "something else"
}
在 XPage 源中查看时:
When viewed in the XPages Source:
<xc:yourControl>
<xc:this.configuration><![CDATA[#{javascript:return {
"groups" : {
"groupA" : {
altName : "A Group",
members : ["me", "you", "them"]
},
"groupB" : {
altName : "B Group",
members : ["him", "her", "they"]
}
},
otherOption : "something else"
}}]]></xc:this.configuration>
现在,要循环执行此操作,您可以轻松地使用绑定到#{compositeData.configuration.groups} 的 xp:repeat 控件,然后所有子"绑定都可以直接完成到为 xp:repeat 定义的变量:
Now, to loop though this, you could easily use an xp:repeat control bound to #{compositeData.configuration.groups}, and then all "child" binding can be done directly to the variable defined for the xp:repeat:
<xp:repeat
value="#{compositeData.configuration.groups}"
indexVar="thisGroup">
<xp:panel tagName="h1">
<xp:text disableTheme="true" value="#{thisGroup.altName}" />
</xp:panel>
<xp:panel tagName="ul">
<xp:repeat value="#{thisGroup.members}" var="thisMember">
<xp:panel tagName="li">
<xp:text disableTheme="true" value="#{thisMember}" />
</xp:panel>
</xp:repeat>
</xp:panel>
</xp:repeat>
使用这种方法,您不受自定义控件属性中包含的大小、范围或内容的限制.
Using this approach, you're not limiting to the size, the scope, nor the content contained within your Custom Control Property.
这篇关于带有允许多个实例的自定义属性组的 xPages 自定义控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!