使用路由器时,Shell 在 SAPUI5 中不显示主(第一) View

标签 shell router sapui5

我在 SAPUI5 应用程序中使用 Shell,如下所示:

var oShell = new sap.ui.ux3.Shell("myShell", {
            showLogoutButton: false,
            showTools:false,
            showPane: false,
            headerType:sap.ui.ux3.ShellHeaderType.SlimNavigation,
            worksetBar:false,

            //Add header items 
            headerItems:[sap.ui.view("login",{type:sap.ui.core.mvc.ViewType.JS, viewName:"prototype.login"})],

            //Add navigation items
            worksetItems:[
                    new sap.ui.ux3.NavigationItem("home", {key:"home",text:"Majas"}), 
                    new sap.ui.ux3.NavigationItem("news", {key:"news",text:"Jaunumi"}),
                    new sap.ui.ux3.NavigationItem("results", {key:"results",text:"Rezultati"}),
                    new sap.ui.ux3.NavigationItem("team", {key:"teams",text:"Komanda"}),                         
                    new sap.ui.ux3.NavigationItem("gallery", {key:"gallery",text:"Galerija"})                  
            ],

            worksetItemSelected:function (oEvent) {
                var sSelected = oEvent.getParameter("id"),
                oHashChanger = sap.ui.core.routing.HashChanger.getInstance();   
                oHashChanger.setHash(oRouter.getURL("_" + sSelected))
        },

        });

然后我使用 Router 将 URL 地址设置为 Shell 中表示的 View ,如下所示:

var oRouter = new sap.ui.core.routing.Router([  {
            pattern: "home",
            name: "_home",
            view: "prototype.home",
            viewType: sap.ui.core.mvc.ViewType.JS,
            targetControl: "myShell",
            targetAggregation: "content",
            clearTarget: true,              
            fireEvent: function() {
                oShell.setSelectedWorksetItem("home");
            }

        },  
        //Adding URL to "news" view
        { 
            pattern: "news",
            name: "_news",
            view: "prototype.news",
            viewType: sap.ui.core.mvc.ViewType.JS,
            targetControl: "myShell",
            targetAggregation: "content",
            clearTarget: true,
            callback: function(oRoute, oArguments) {
                oShell.setSelectedWorksetItem("news");
            }
        },

        {
            pattern: "results",
            name: "_results",
            view: "prototype.resultsVirsliga",
            viewType: sap.ui.core.mvc.ViewType.JS,
            targetControl: "myShell",
            targetAggregation: "content",
            clearTarget: true,
            callback: function(oRoute, oArguments) {
                oShell.setSelectedWorksetItem("results");
            }
        },

        {
            pattern: "team",
            name: "_team",
            view: "prototype.team",
            viewType: sap.ui.core.mvc.ViewType.JS,
            targetControl: "myShell",
            targetAggregation: "content",
            clearTarget: true,
            callback: function(oRoute, oArguments) {
                oShell.setSelectedWorksetItem("team");
            }
        },

        {
            pattern: "image",
            name: "_gallery",
            view: "prototype.image",
            viewType: sap.ui.core.mvc.ViewType.JS,
            targetControl: "myShell",
            targetAggregation: "content",
            clearTarget: true,
            callback: function(oRoute, oArguments) {
                oShell.setSelectedWorksetItem("gallery");
            }
        },

        {
            pattern: "login",
            name: "_login",
            view: "prototype.login",
            viewType: sap.ui.core.mvc.ViewType.JS,
            targetControl: "myShell",
            targetAggregation: "content",
            clearTarget: true,
            callback: function(oRoute, oArguments) {
                oShell.setSelectedHeaderItem("login");
            }
        }
    ]);
    oRouter.initialize();

一切正常,除了首先(主视图),当我打开我的应用程序(主视图)时,它显示空白页面,只有导航可见,然后我导航到其他页面,然后返回主页,所有内容都会出现,然后工作正常。 为什么当我进入页面时 View 不加载,而只有当我导航到其他 View 然后返回时才加载?

最佳答案

要在路由器中默认加载主视图,请将其定义如下并带有模式空间。

 pattern: "",
   name: "_home",
   view: "prototype.home",
   viewType: sap.ui.core.mvc.ViewType.JS,
   targetControl: "myShell",
   targetAggregation: "content",
   clearTarget: true,
   fireEvent: function() {
     oShell.setSelectedWorksetItem("home");
   }

虽然这是一个老问题,但它可能会帮助将来的人,因为它帮助我解决了同样的问题:)

关于使用路由器时,Shell 在 SAPUI5 中不显示主(第一) View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23695507/

相关文章:

linux - Linux 中的 readlink -f 是否有任何方法/替代方法来处理文件夹名称中存在的空格?

javascript - OData V2 模型上的 Kapsel 离线应用程序的 SAPUI5 深度插入

linux - 如何检查文件是否存在但在 shell 脚本的路径中间泛化?

docker - shell脚本在cron作业中不起作用 docker

linux - 是否可以通过带括号调用来执行shell中的函数

linux - ip 转发在 CentOS7 上的 netns 内不起作用

linux - wifidog认证服务器请求http ://serverdomain/install/3 got an error

javascript - 将 hoist-non-react-statics 与 withRouter 一起使用

javascript - 带有多个窗口的弹出窗口(如 sap.m.dialog)

javascript - 通过Id获取sapui5元素Like