Passing Data from Master to Detail Page

后端 未结 3 1269
隐瞒了意图╮
隐瞒了意图╮ 2020-12-18 03:31

I watched some tutorials about navigation + passing data between views, but it doesn\'t work in my case. My goal is to achieve the follwing:

  1. On the MainPage th
3条回答
  •  忘掉有多难
    2020-12-18 04:16

    The recommended way to pass data between controllers is to use the EventBus

    sap.ui.getCore().getEventBus();
    

    You define a channel and event between the controllers. On your DetailController you subscribe to an event like this:

    onInit : function() {
        var eventBus = sap.ui.getCore().getEventBus();
        // 1. ChannelName, 2. EventName, 3. Function to be executed, 4. Listener
        eventBus.subscribe("MainDetailChannel", "onNavigateEvent", this.onDataReceived, this);)
    },
    
    onDataReceived : function(channel, event, data) {
       // do something with the data (bind to model)
       console.log(JSON.stringify(data));
    }
    

    And on your MainController you publish the Event:

    ...
    //Navigation to the Detail Form
    app.to(page,"flip");
    var eventBus = sap.ui.getCore().getEventBus();
    // 1. ChannelName, 2. EventName, 3. the data
    eventBus.publish("MainDetailChannel", "onNavigateEvent", { foo : "bar" });
    ...
    

    See the documentation here: https://openui5.hana.ondemand.com/docs/api/symbols/sap.ui.core.EventBus.html#subscribe

    And a more detailed example: http://scn.sap.com/community/developer-center/front-end/blog/2015/10/25/openui5-sapui5-communication-between-controllers--using-publish-and-subscribe-from-eventbus

提交回复
热议问题