2014-10-02 77 views
0

我创建了具有属性定义组的自定义控件。本集团已选中“允许多个实例”。当我在xPage上放置控件时,我可以通过UI手动添加2项到属性并设置组的子属性,但我需要弄清楚如何通过循环访问数组来编程地填充组,做一些计算。xPages自定义控件与允许多个实例的自定义属性组

回答

0

在引导程序进度条的自定义控件中,我有一个名为BarDetail的属性组。有3个属性:样式,宽度和顺序。并打开多个实例。

下面是关于如何访问属性的XML。我相信,我也谈到了这个在视频上NotesIn9 151(http://www.notesin9.com/2014/08/10/notesin9-151-bootstrap-progressbars-in-xpages/

<xp:panel styleClass="progress"> 
      <xp:repeat 
       id="repeat1" 
       rows="30" 
       var="rowData" 
       indexVar="rowIdx" 
       disableOutputTag="true"> 
       <xp:this.value><![CDATA[#{javascript:var object = compositeData.BarDetail; 
var tree:java.util.TreeMap = new java.util.TreeMap(); 
var data:java.util.ArrayList = compositeData.BarDetail; 

var total = 0; 
var count = 0; 


// first Loop is to build the map and get the count. 
for (x in data) { 
    count++; 
    tree.put(x["order"].toString(), x); 
// print("Width : " + x["width"]); 
// var wCount:string = x["width"]; 

    total = total + Number(x["width"]); 
// print("Loop count : " + count); 

} 

    // We want all the colors to expand to 100% 

    // Now we need to scale the percentages 
    var count = 0; 


    var itr:Iterator = tree.values().iterator(); 
    while(itr.hasNext()) { 
     var tempBar = itr.next(); 
     tempBar["width"] = (tempBar["width"]/total) * 100 
    } 




return tree.values()}]]></xp:this.value> 

       <xp:text 
        escape="true" 
        id="computedField1" 
        tagName="div"> 
        <xp:this.styleClass><![CDATA[#{javascript:rowData["style"]}]]></xp:this.styleClass> 
        <xp:this.style><![CDATA[#{javascript:return "width: " + rowData["width"] + "%;"}]]></xp:this.style> 
       </xp:text> 
      </xp:repeat> 

     </xp:panel> 
+0

没有问题使用compositeData.groupname [I] .propertyname类型的语法访问控件本身的属性。但在另一端,我将属性发送给控件。我想以编程方式执行该操作,这就是我遇到问题的地方。所以以非常相似的方式。我的组名为Columns,并具有以下属性:Width,IsTotalled,Caption,columnID。如果通过界面我可以手动设置这些属性,它看起来像这样: – 2014-10-03 20:28:33

+0

2014-10-03 20:36:49

2

我倾向于定义一个定制控件属性命名为“配置”,并设置为“对象”(你有键入在主场迎战从下拉列表中选择):

Custom Control Property: configuration

现在,你可以把一个对象作为你的财产:

return { 
    "groups" : { 
    "groupA" : { 
     altName : "A Group", 
     members : ["me", "you", "them"] 
    }, 
    "groupB" : { 
     altName : "B Group", 
     members : ["him", "her", "they"] 
    } 
}, 
    otherOption : "something else" 
} 

当在XPages中源看:现在

<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> 

,循环尽管这样,你可以很容易地使用XP:重复绑定到#{} compositeData.configuration.groups控制,然后所有的“孩子”绑定可以做到直接到达XP定义的变量:重复:

<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> 

使用这种方法,你不再受限于规模,范围,也不包含在您的自定义控制属性中的内容。