从UI5中的Radiobutton检索键值(xml视图)

时间:2015-10-20 09:31:29

标签: sapui5



sap.ui.controller("test.controller", {
        
onInit: function() {
	var aData = {
		      items: [
		      {
		        ATNAM: "FIORI_PRG",
		        ATWRT: "BA",
		        ATWTB: "Barcelona"
		      }, {
		        ATNAM: "FIORI_PRG",
		        ATWRT: "BE",
		        ATWTB: "Berlin"
		      }, {
		        ATNAM: "FIORI_PRG",
		        ATWRT: "HA",
		        ATWTB: "Havanna"
		      }, {
		        ATNAM: "FIORI_TYP",
		        ATWRT: "SE",
		        ATWTB: "Sessel"
		      }, {
		        ATNAM: "FIORI_TYP",
		        ATWRT: "ZW",
		        ATWTB: "Zweisitzer"
		      }, {
		        ATNAM: "FIORI_TYP",
		        ATWRT: "DR",
		        ATWTB: "Dreisitzer"
		      }, {
		        ATNAM: "FIORI_FARBE",
		        ATWRT: "BL",
		        ATWTB: "Blau"
		      }, {
		        ATNAM: "FIORI_FARBE",
		        ATWRT: "BR",
		        ATWTB: "Braun"
		      }, {
		        ATNAM: "FIORI_FARBE",
		        ATWRT: "GR",
		        ATWTB: "Grün"
		      }, {
		        ATNAM: "FIORI_FARBE",
		        ATWRT: "SW",
		        ATWTB: "Schwarz"
		      }, {
		        ATNAM: "FIORI_BEZUGSSTOFF",
		        ATWRT: "ST",
		        ATWTB: "Stoff"
		      },  {
		        ATNAM: "FIORI_BEZUGSSTOFF",
		        ATWRT: "KL",
		        ATWTB: "Kunstleder"
		      },  {
		        ATNAM: "FIORI_BEZUGSSTOFF",
		        ATWRT: "NL",
		        ATWTB: "Naturleder"
		      } ],
		    };

		    var oModel = new sap.ui.model.json.JSONModel();
		    oModel.setData(aData);
		    sap.ui.getCore().setModel(oModel);
		  },
  
radiobuttonselect:function(oEvent){
    var oSelectedIndex = oEvent.getParameter("selectedIndex");  
    var oRadioButtonSrc = oEvent.getSource().getAggregation("buttons");  
    var oSelectedRadio = oRadioButtonSrc[oSelectedIndex].getText();
//oRadioButtonSrc[oSelectedIndex].getKey(); does not work
    alert(oSelectedRadio);
	},
 
		});

    var oView = sap.ui.xmlview({
        viewContent: jQuery("#view1").html()
    });
    oView.placeAt("content");

<!DOCTYPE html>
<html>
<head>
  <meta name="description" content="OpenUI5 BIN Starting template" />
  <meta http-equiv="X-UA-Compatible" content="IE=edge" />
  <meta charset="utf-8">
    <script id="sap-ui-bootstrap" 
    type="text/javascript"
    data-sap-ui-libs="sap.ui.table,sap.ui.commons"
    data-sap-ui-theme="sap_bluecrystal" src="https://sapui5.hana.ondemand.com/resources/sap-ui-core.js"></script>
<script id="view1" type="sapui5/xmlview">
<sap.ui.core.mvc:View controllerName="test.controller"
    xmlns:c="sap.ui.commons"
    xmlns:k="sap.ui.core"
    xmlns:sap.ui.core.mvc="sap.ui.core.mvc">
    
    
   <RadioButtonGroup xmlns="sap.m" id="Typ" buttons="{/items}" width="500px" columns="1" enabled="true" class="sapUiMediumMarginBottom" select="radiobuttonselect"> 
      <buttons>                                                    <RadioButton id="RBG1" text="{ATWTB}" key="{ATWRT}"/>
      </buttons>                                        	</RadioButtonGroup>
</sap.ui.core.mvc:View>

</script>

  <title>buttons Vs Combobox</title>
</head>

<body class="sapUiBody">
  <div id="content"></div> 
</body>
</html>
&#13;
&#13;
&#13;

你好专家, 这个问题是要从radiobutton中检索一个关键值。要检索文本是可能的(如上面的代码片段所示),但我很难获得键值(这是我的尝试:http://jsbin.com/yoxube/edit?html,js,output)。可能吗?会是什么样的?谢谢你提前和最好的问候, 加布里埃尔

1 个答案:

答案 0 :(得分:1)

您好,

我将如何操作(我将在此处发布您更新的radiobuttonselect()函数):

radiobuttonselect:function(oEvent){
    var oSelectedIndex = oEvent.getParameter("selectedIndex");  
    var oRadioButtonSrc = oEvent.getSource().getAggregation("buttons");  
    var oModel = sap.ui.getCore().getModel();  
    var sKey = oModel.getProperty("/items/"+oSelectedIndex+"/ATWRT"); 
    alert(sKey);
},

这是一个有效的JSBIN:LINK