如何检索作为 InputListItem 一部分并具有聚合绑定的 RadioButton 的绑定属性的值?

洛基

我正在尝试的 jsbin 上有以下代码。我需要获取模型“答案”中提到的“Id”属性的值。直到现在,在尝试时我才明白我需要使用 select 事件来提醒选定的值。我也尝试使用event.getSource().getSelectedItem().getBindingContext().getObject().Id但我无法获得“Id”属性值。您可以在 jsbin 下方找到我正在尝试的代码:http ://jsbin.com/peciqaq/1/edit?html,output

Haojie

您必须Id从绑定模型中获取。

将您的onSelectRadio事件处理程序更改为以下内容:

if(!event.getParameter("selected")) return;
var oModel = event.getSource().getModel();
var sPath = event.getSource().getBindingContext().getPath()
alert(oModel.getProperty(sPath+"/Id"));

<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta charset="UTF-8">

        <title>List example</title>
      
        <script id="sap-ui-bootstrap" 
                type="text/javascript"
                src="https://openui5.hana.ondemand.com/resources/sap-ui-core.js"
                data-sap-ui-theme="sap_bluecrystal"
                data-sap-ui-libs="sap.ui.commons, sap.m"
                data-sap-ui-xx-bindingSyntax="complex">
        </script>


        <!-- XML-based view definition mode="SingleSelectMaster" -->
        <script id="view1" type="sapui5/xmlview">
            <mvc:View
              controllerName="local.controller"
              xmlns:core="sap.ui.core"
              xmlns:f="sap.ui.layout.form"
              xmlns:l="sap.ui.layout"
              xmlns:mvc="sap.ui.core.mvc"
              xmlns="sap.m">
          <List
	       	headerText="Awesome List"
		    items="{/answers}"
            id="singleChoice"
            selectionChange="onSelectionChange">
		    <items>
			  <InputListItem label="{answerText}">
                <RadioButton select="onSelectRadio"/>
              </InputListItem>
		    </items>
	      </List>
          
          </mvc:View> 
        </script>

        <script>

            // Controller definition
            sap.ui.controller("local.controller", {
              onInit: function() {
                var oData =   {
                  "answers": [{
                      "Id":1,
                      "answerText": "Cats"
                  }, {
                      "Id":2,
                      "answerText": "Rabbits"
                  }, {
                      "Id":3,
                      "answerText": "Dogs"
                  }, {
                      "Id":4,
                      "answerText": "Hamsters"
                  }]
                };
                sap.ui.getCore().setModel(new sap.ui.model.json.JSONModel(oData));
              },
              /*onSelectionChange: function(event) {
                alert(event.getSource().getSelectedItem().getBindingContext().getObject().Id);
                console.log(JSON.stringify(event.getSource().getSelectedItem().getBindingContext().getObject()));
              },*/
              onSelectRadio: function(event){
				if(!event.getParameter("selected")) return;
				var oModel = event.getSource().getModel();
				var sPath = event.getSource().getBindingContext().getPath()
				alert(oModel.getProperty(sPath+"/Id"));
                //alert(this.byId("singleChoice").getSelectedItem());
                //alert(event.getSource().getSelectedItem().getBindingContext().getObject().Id);
              }
            });
           
            // Instantiate the View, assign a model
            // and display
            var oView = sap.ui.xmlview({
                viewContent: jQuery('#view1').html()
            });
               
            oView.placeAt('content');

        </script>

    </head>
 
    <body class="sapUiBody" role="application">
        <div id="content"></div>
    </body>
</html>

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

如何使用系统环境变量作为@PropertySource值的一部分?

如何删除哈希值的一部分?

如何使用Hibernate更新所有实体属性的仅一部分

如何获得class属性值的一部分?

如何使用猫鼬查找获取包含字符串一部分的所有值?

将RadioButton绑定到单个属性?

如何提取属性内值的一部分

WPF + MVVM + RadioButton:具有单个属性的句柄绑定

Windows窗体RadioButton列表-将Enum属性绑定到RadioButton

Sequelize中的异步获取器/设置器作为属性的一部分

如何保证属性是接口的一部分?

对Teradata选举的非聚合值进行分区时具有分析功能的聚合函数必须是关联组的一部分

使用图遍历的一部分的属性作为其他的过滤器

如何在具有多个值的列中选择字符串的一部分

如何在使用mvvm模型时在zk中绑定字符串的一部分

使用程序包设置启用/禁用键绑定(作为键绑定上下文列表的一部分)

如何将RadioButton与DataGridTextColumn绑定?

WindowsFolder属性作为exe地址的一部分不起作用

使用SimpleXml只检索属性内容的一部分:YouTube视频ID

WPF RadioButton命令绑定

如何将 ASP.NET 控制器属性与当前 URL 的一部分绑定?

如何绑定已经绑定的变量的一部分

如何使用 Pandas 为与多部分索引的一部分匹配的所有行设置值

如何访问作为对象数组一部分的对象内的数组的值?

Symfony 3.4:如何针对不属于绑定到表单的实体的一部分的“外部”值进行验证

OpenCV - 如何为图像的一部分中的所有像素添加一个值?

是否可以使用 xpath 将 $ 作为属性名称的一部分

使用参数作为对象属性链的一部分

如何使用 JS 将 JS var 作为元素属性的一部分