简体   繁体   English

在Fiori Launchpad标头事件的事件处理程序中获取oData

[英]Getting the oData in the event handler of Fiori Launchpad header event

I would like to check for data changes when the user clicks on the back button in the Fiori Launchpad. 当用户单击Fiori Launchpad中的“后退”按钮时,我想检查数据是否更改。 I have the following code 我有以下代码

onAfterRendering: function() {
        sap.ui.getCore().byId("backBtn").attachPress(this, function(oEvent) {
            oEvent.preventDefault();
        }); 
}

Within the function I would like to access the oData and other variables of the main controller. 在函数中,我想访问oData和主控制器的其他变量。 However when I press the back button the "this" object is the header control's view. 但是,当我按下后退按钮时,“ this”对象就是标题控件的视图。

How can get the view of the page content and also access the oData and other parameters of the controller associated to the content view. 如何获取页面内容的视图以及如何访问oData和与内容视图关联的控制器的其他参数。

In order to access the current context you have to call the event handler function within that specific context, so therefore a binding is needed on that function. 为了访问当前上下文,您必须在特定上下文中调用事件处理函数,因此需要在该函数上进行绑定。

onAfterRendering: function() {
        sap.ui.getCore().byId("backBtn").attachPress(this, function(oEvent) {
            oEvent.preventDefault();
        }.bind(this)); 
}

If usage of sap.m.Page is an option than navButtonPress builtin event can be used: 如果使用sap.m.Page是一个选项,则可以使用navButtonPress内置事件:

View.xml : View.xml

<mvc:View xmlns="sap.m" xmlns:mvc="sap.ui.core.mvc">
    <Page navButtonPress="onNavBack">
    ...

Controller.js : Controller.js

    onNavBack: function(oControlEvent) {
        var oController = this;
        var oView = this.getView();
    }

the event listener will be triggered every time the button is pressed in the Fiori Launchpad header. 每次在Fiori Launchpad标头中按下按钮时,都会触发事件监听器。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM