Navigation Problems in a sapui5 unified Shell (sap

2019-02-25 18:46发布

问题:

I have used unified Shell control in order to implement the facebook-like swipe menu and I integrated in it a list so that I can enter menu items. The idea is that when a user clicks on a certain list item in the menu he will get redirected to a new view. I tried to implement it by using bus.publish("nav", "to" {id:..}) but it's not working. (I have put the menu in the Curtain Pane of the Unified Shell) Can anybody help me? You can find below the respective code snippets of the view and controller.

var oListTemplate = new sap.m.StandardListItem({
            title: "{title}",
            icon: "{icon}",
            description: "{description}",
            type: sap.m.ListType.Navigation,
            customData: new sap.ui.core.CustomData({
                key: "targetPage",
                value: "{targetPage}"
            })
        });

        var oList = new sap.m.List({
            selectionChange: [oController.doNavOnSelect, oController],
            mode: sap.m.ListMode.SingleSelectMaster
        });
        oList.bindAggregation("items", "/Menu", oListTemplate);

The controller:

onInit: function() {

        this.getView().setModel(new sap.ui.model.json.JSONModel("model/menu.json"));
       this.bus = sap.ui.getCore().getEventBus();
    },


 doNavOnSelect: function(event){
     if (sap.ui.Device.system.phone) {
            event.getParameter("listItem").setSelected(false);
        }
     this.bus.publish("nav", "to", {
            id: event.getParameter('listItem').getCustomData()[0].getValue()
        });

回答1:

Navigation via the sap.ui.core.EventBus is obsolete. Please have a look at SAPUI5 Navigation and Routing http://help.sap.com/saphelp_hanaplatform/helpdata/en/68/8f36bd758e4ce2b4e682eef4dc794e/content.htm

A new Routing mechanism was introduced to UI5 in release 1.16. For in-app navigation, this supersedes previous techniques such as using the sap.ui.core.EventBus or sharing navigation-container specific controller code amongst aggregated pages.



回答2:

Solution: Replace bus.publish with app.to

doNavOnSelect: function(event){
    if (sap.ui.Device.system.phone) {
            event.getParameter("listItem").setSelected(false);
        }

    app.to(event.getParameter('listItem').getCustomData()[0].getValue());

    }