2017-07-14 56 views
0

我在應用程序中有兩個分段按鈕項目作爲Delivery和Collection,我想通過從前端將Delivery作爲「D」標誌和Collection作爲「C」標誌來區分兩個按鈕,以知道哪個按鈕被點擊(這兩個按鈕包含一組輸入數據的字段)。由於我是新來的自定義SAUI5應用程序,我不知道如何通過這個單獨的。專家請幫助我。 下面是我的代碼,SAPUI5分段按鈕選擇

<SegmentedButton selectedKey="small" id="idSegment"> 
    <items> 
    <SegmentedButtonItem id="idSegDel" text="Delivery" key="delKey" press="handleDelivery" /> 
    <SegmentedButtonItem id="idSegColl" text="Collection" key="colKey" press="handleCollection" enabled="true" /> 
    </items> 
</SegmentedButton> 

handleCollection: function() { 
    this.byId("idPanelDimension").setVisible(true); 
    this.byId("idPanelDimension1").setVisible(true); 
}, 

handleDelivery: function() { 
    this.byId("idPanelDimension").setVisible(false); 
    this.byId("idPanelDimension1").setVisible(false); 
    this.byId("idWeight").setValue(""); 
    this.byId("idLength").setValue(""); 
    this.byId("idBreadth").setValue(""); 
    this.byId("idHeight").setValue(""); 
}, 
    OnCreate : function(){ 
    var oflagSeg = "D"; //this is only for D Flag but i need to set for both as if Delivery D is clicked or Collection C cliked. 
    var oEntry = {Flag: oflagSeg,} //Passing odata attribute 
} 

回答

0

感謝您的想法,我已經做了,和完美的作品,下面是我的代碼。

var oflagSeg = ""; 
    var mainseg = sap.ui.getCore().byId("idRetDel1--idSegment").getSelectedKey(); 
    if(mainseg == "keyDel"){ 
     oflagSeg = "D"; 
    }else if(mainseg == "keyCol"){ 
     oflagSeg = "C"; 

    } 
0

你不應該使用單獨的新聞發佈會上爲每個按鈕,因爲它是分段按鈕的聚合控制。使用分段按鈕控件中的「選擇」事件並獲取所選按鈕的按鍵。請通過下面的鏈接,我已經寫了代碼。

http://veui5infra.dhcp.wdf.sap.corp:8080/snippix/snippets/34075

+0

您還可以使用selectedKey屬性在加載視圖上設置所選按鈕的默認值。 –