Javascript SAPUI5分段按钮选择
在我的应用程序中,我有两个分段的按钮项作为传递和收集,我想通过从前端传递传递传递作为“D”标志和收集作为“C”标志来区分这两个按钮,以了解单击了哪个按钮(这两个按钮包含一组输入数据的字段)。由于我是定制SAUI5应用程序的新手,我不知道如何将其单独传递。请专家们帮我。 下面是我的代码Javascript SAPUI5分段按钮选择,javascript,html,css,xml,Javascript,Html,Css,Xml,在我的应用程序中,我有两个分段的按钮项作为传递和收集,我想通过从前端传递传递传递作为“D”标志和收集作为“C”标志来区分这两个按钮,以了解单击了哪个按钮(这两个按钮包含一组输入数据的字段)。由于我是定制SAUI5应用程序的新手,我不知道如何将其单独传递。请专家们帮我。 下面是我的代码 <SegmentedButton selectedKey="small" id="idSegment"> <items> <SegmentedButtonItem i
<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
}
handleCollection:function(){
此.byId(“idPanelDimension”).setVisible(真);
此.byId(“idPanelDimension1”).setVisible(true);
},
handleDelivery:函数(){
此.byId(“idPanelDimension”).setVisible(假);
此.byId(“idPanelDimension1”).setVisible(false);
此.byId(“idWeight”).setValue(“”);
此.byId(“idLength”).setValue(“”);
此.byId(“idBreadth”).setValue(“”);
此.byId(“idHeight”).setValue(“”);
},
OnCreate:function(){
var of lagseg=“D”;//这仅适用于D标志,但我需要为这两个标志设置,就好像单击了传递D或单击了集合C一样。
var oEntry={Flag:oflagSeg,}//传递odata属性
}
您不应该对每个按钮单独使用press event,因为它是分段按钮的聚合控件。在分段按钮控件中使用“选择”事件,获取所选按钮的键。请通过下面我编写代码的链接
谢谢你的想法,我已经做到了,而且效果很好,下面是我的代码
var oflagSeg = "";
var mainseg = sap.ui.getCore().byId("idRetDel1--idSegment").getSelectedKey();
if(mainseg == "keyDel"){
oflagSeg = "D";
}else if(mainseg == "keyCol"){
oflagSeg = "C";
}
您还可以使用selectedKey属性在加载视图时设置所选按钮的默认值。