【问题标题】:Retrieve Key value from Radiobutton in UI5 (xml View)从 UI5 中的 Radiobutton 中检索键值(xml 视图)
【发布时间】:2015-10-20 09:31:29
【问题描述】:

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>

各位专家,您好, 这个问题即将从单选按钮中检索一个键值。检索文本是可能的(如上面的 sn-p),但我很难获得键值(这是我的尝试:http://jsbin.com/yoxube/edit?html,js,output)。可能吗?怎么办?提前谢谢你和最好的问候, 加布里埃尔

【问题讨论】:

    标签: sapui5


    【解决方案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

    【讨论】:

    • 非常感谢。 getCore 和 getModel 的概念是我仍然必须学习的。再次感谢您
    • @GabrielGomez 不客气!随意将答案标记为正确;)
    • 嗨@keshet 当然我试过了,但系统还不允许我。一旦我获得 15 个声望点,我会将您的答案标记为正确。再次感谢您。
    猜你喜欢
    • 2014-08-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-02-22
    • 1970-01-01
    • 2020-08-19
    相关资源
    最近更新 更多