2014-10-02 90 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> 

使用這種方法,你不再受限於規模,範圍,也不包含在您的自定義控制屬性中的內容。