Fiori app - getContext on SAPUI5 details page

I am on my way to creating an application Fioriusing SAPUI5. I successfully built the page Master, and when I clicked on an element, I set the context and went to the page Detail.

The context path from the main page is something like "/ SUPPLIER (" NAME ")". The function is as App.controoler.jsfollows:

handleListItemPress : function (evt) {
        var context = evt.getSource().getBindingContext();
        this.nav.to("Detail", context);

But I would like to know how I can access this contexton the page deatil. I need this because I need to use $expandto create a URL and bind the elements to a table.

Any suggestions would be highly appreciated.

thank

+4
source share
2 answers

The UI5 Documentation provides an example of how to deal with this problem by using a EventDelegatefunction onBeforeShowthat is automatically called by the framework. I adapted it to your use case:

app.to("detailPage", context); 
// trigger navigation and hand over a data object

// and where the detail page is implemented:
myDetailPage.addEventDelegate({
   onBeforeShow: function(evt) {
      var context = evt.data.context;
   }
});

You can decide whether to use addEventDelegateor (which I prefer) to write the function onBeforeShow in your target view . This could be your target view:

onBeforeShow(evt) {
    // get your data from the evt object
    var context = evt.data.context;
},

getControllerName : function() {
    ...
},


createContent : function() {
    ...
},  

The object evt.datacontains all the data that you put in app.to(id, data). You can write it to the console to see the structure of the evt object.

Let me know if you have further questions.

0
source

Please refer to the Basket example in the SAP UI5 Demo Kit.

https://sapui5.hana.ondemand.com/sdk/test-resources/sap/m/demokit/cart/index.html?responderOn=true

, "Component.js" .

, . . .

Component.js:

routes: [
      { pattern: "cart",
        name: "cart",
    view: "Cart",
    targetAggregation: "masterPages"
      }
        ]

Cart.controller.js .

    onInit : function () {
         this._router = sap.ui.core.UIComponent.getRouterFor(this);
         this._router.attachRoutePatternMatched(this._routePatternMatched, this);
   },

    _routePatternMatched : function(oEvent) {
    if (oEvent.getParameter("name") === "cart") {
        //set selection of list back
        var oEntryList = this.getView().byId("entryList");
        oEntryList.removeSelections();
    }
}

, .

0

Source: https://habr.com/ru/post/1532971/


All Articles