参数传递 – 如何在XML视图SAP UI5中将参数传递给事件处理程序
我无法将数据从
XML视图发送到控制器.在JS视图中很容易实现.
例如:- 在JS视图中: – var btn = new sap.m.Button({ text:"click",tap:function(){ callFunction(oEvent,"mycustomString"); } }); 如何使用XML视图实现相同的功能. <Button text="click" tap="callFunction"/> 以上只会传递事件而不是“mycustomString”.
这是一个老问题,但
as of version 1.56现在支持直接在XML视图中将参数传递给处理函数.
所以你现在可以这样做: <Button text="click" tap=".callFunction($event,'mycustomString')" /> 请注意,只要您传递至少一个参数,事件本身将不再自动传递,因此您需要通过传递$event手动执行此操作,如上所述.但是,还有其他语法可以直接传递事件参数,源代码控制和数据绑定,因此您可能根本不需要该事件. 该功能的文档可在Demo Kit在线获得. 简短演示: sap.ui.define([ "sap/ui/core/mvc/Controller" ],function(Controller) { "use strict"; return Controller.extend("myController",{ callFunction: function(sButtonText,sVal) { alert("Clicked " + sButtonText + " with value " + sVal); } }); }); sap.ui.xmlview({ viewContent: $('#myView').html() }).placeAt('content'); <html> <head> <meta charset="utf-8"> <script id='sap-ui-bootstrap' src='https://sapui5.hana.ondemand.com/resources/sap-ui-core.js' data-sap-ui-libs='sap.m'></script> <script id="myView" type="sapui5/xmlview"> <mvc:View controllerName="myController" xmlns:mvc="sap.ui.core.mvc" xmlns="sap.m"> <Button text="Button 1" press=".callFunction(${$source>/text},'ABCDEF')" /> <Button text="Button 2" press=".callFunction(${$source>/text},'UVWXYZ')" /> </mvc:View> </script> </head> <body class='sapUiBody'><div id='content'></div></body> </html> (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |