2014-05-09 29 views
1

我在名爲「Add Line Item」的視圖中有一個按鈕。您選擇一個文檔,然後點擊此按鈕。目的是我們創建一個新文檔,其中所選文檔的值被填入新文檔中。在beforePageLoad事件中設置組合框的值

在視圖按鈕中,我使用長字符串設置了sessionScope變量。我用「〜」分隔每個條目。在每個條目中,第一件事是該字段的實際名稱。接下來是該領域的價值。這兩個由管道「|」分隔。如果字段的實際值是一個數組,他們自然會用分號分隔它們。我提到所有這些,以便下面的代碼可以被理解。

在我啓動的窗體中,在beforePageLoad事件中,我有以下幾點:

var AddingNewLine = sessionScope.get("AddingNewLine"); 
if (AddingNewLine != null) { 
    fieldsArray = AddingNewLine.split("~"); // make an array that has the field names & its value(s) 
    for (i = 0 ; i < fieldsArray.length ; i++) { 
    splitValue = fieldsArray[i].split("|"); // now we make an array out of the entry. value 0 will be 
    fieldName = splitValue[0];    // the name of the field. value 1 will be the values which 
    fieldValues = splitValue[1].split(";") // in turn will be split into an array 
    var f = "PayRates:HourlyRates:CPrompts:IssuingCountry:ServiceCurrency:ReceivedDate:InvoiceDate:Client:InvoiceNumber:WBS"; 
    if (f.search(fieldName) >= 0) { 
     currentDocument.setValue(fieldName,fieldValues); 
     if (fieldName == "CPrompts") { var CPrompts = fieldValues } 
    } 
    } 
// new doc but adding new line item or replicating? then get our prompts from the original doc 
for (i = 0; i < CPrompts.length ; i++) {sessionScope.put("CPrompt"+(i+1),CPrompts[i])} 
} 

注:我篩選出的數值與「F」變量現在,因爲我跟他們不同的問題

反正,我所有的文本框都得到更新,但組合框不是(這恰好是IssuingCountry,ServiceCurrency,Client和WBS)

我已經驗證過,當我執行currentDocument.setValue時,字段名稱及其值與print語句是正確的。做一個currentDocument.replaceItemVale。似乎不適用於comboBox類型字段。這也適用於日期值字段。

組合框領域例如:

<xp:comboBox 
    id="IssuingCountry" 
    style="width:160.0px" 
    value="#{FInvoiceDoc.IssuingCountry}"> 
    <xp:selectItem 
     itemLabel="United States of America" 
     itemValue="United States of America" 
     id="selectItem1"> 
    </xp:selectItem> 
    <xp:selectItems id="selectItems1"> 
     <xp:this.value> 
     <![CDATA[#{javascript:@DbLookup("", "Keywords", "Countries", 2)}]]> 
    </xp:this.value> 
    </xp:selectItems> 
</xp:comboBox> 

難道是因爲我需要以某種方式更新itemLabel?如果是這樣,怎麼樣?

日期字段示例;

<xp:inputText 
    value="#{FInvoiceDoc.ReceivedDate}" 
    id="ReceivedDate" 
    style="width:85px"> 
    <xp:this.converter> 
     <xp:convertDateTime 
     pattern="MM/dd/yyyy"> 
     </xp:convertDateTime> 
    </xp:this.converter> 
    <xp:dateTimeHelper 
    id="dateTimeHelper1"> 
    </xp:dateTimeHelper> 
</xp:inputText> 

回答

1

會話範圍可以處理複雜的對象。創建一個字符串會降低可維護性。我想創建這樣的東西:

var prepopulate = []; 
    prepopulate.push({ "name" : "IssuingCountry", value : "United Stated of America"}); 
    prepopulate.push({ "name" : "ReceivedDate", value : [date1, date2]); 

    sessionScope.AddingNewLine = prepopulate; 

然後就是afterPageLoad(其中renderResponse之前運行),你做這樣的事情(省略測試有效的字段名):

if (!sessionScope.AddingNewLine) { 
    return; 
    } 
    var prepopulate = sessionScope.AddingNewLine; 

for(var i = 0; i < prepopulate.length; i++) { 
    var oneItem = prepopulate[i]; 
    FInvoiceDoc.setValue(oneItem.name, oneItem.value); 
} 

    // reset 
sessionScope.AddingNewLine = null; 

所以2重要的區別:使用afterPageLoad並使用複雜的對象,而不是通配符。由於您對CPrompts有特殊用途,因此您可能需要使用對象而不是陣列。

btw你聲明一個條件內的變量。只有JS不使用塊級別變量才能防止代碼在您的字符串中沒有CPrompts時失敗。因此,複雜的對象可能是:

var prepopulate = {}; 
prepopulate.cprompts = ["some","prompts"]; 
prepopulate.fields = []; 
prepopulate.fields.push(....); 

希望幫助

+0

感謝您向我展示數組的名稱和值集成開發環境。儘管如此,仍然有完全相同的問題。組合框和日期不更新。以下是我使用其中一個代碼填充的代碼; prepopulate.push({「name」:「IssuingCountry」,值:doc.getFirstItem(「IssuingCountry」)。getValues()}); – cjames728

+0

啊,我需要getValueString。這是行得通的。謝謝! – cjames728

+0

名稱/值是JavaScript對象的一部分。你既不限於2個屬性也不限於名稱。您可以將其稱爲字段/內容並添加數據類型屬性。這就是爲什麼JSON非常受歡迎 – stwissel

1

或者你可以給UNID選擇文件的參數與類似的東西:

context.redirectToPage("issue.xsp?action=newDocument&parentId=" + selectedUNID); 

和beforePageLoad,檢索parentDoc得到所有需要的字段

if (dataDoc.isNewNote()) { 
    var sParentId = dataDoc.getParentId(); 
    if (sParentId != null) { 
     var parentDoc:NotesDocument = database.getDocumentByUNID(sParentId); 

     dataDoc.setValue("KeyParent", parentDoc.getItemValueString("KeyDoc")); 
     dataDoc.setValue("Domain", parentDoc.getItemValueString("Domain")); 
    } 
} 
+0

這也是一種可能性。我通常會迴避這種方法,因爲您可能具有來自配置文件或計算出的值。接收端使用該對象時需要知道這些值是如何組成的 – stwissel