简体   繁体   English

单击按钮在浏览器的新选项卡中打开 sapui5 详细信息页面

[英]open sapui5 detail page in a new tab of the browser on click of a button

<!DOCTYPE HTML>
<html>
    <head>
        <meta http-equiv="X-UA-Compatible" content="IE=edge">

        <script src="resources/sap-ui-core.js"
                id="sap-ui-bootstrap"
                data-sap-ui-libs="sap.m,sap.ui.table,sap.ui.commons"
                data-sap-ui-theme="sap_bluecrystal">
        </script>
        <!-- only load the mobile lib "sap.m" and the "sap_mvi" theme -->

        <script>
                var bFlag;
                sap.ui.localResources("views");
                sap.ui.localResources("i18n");
                sap.ui.localResources("utils");
                jQuery.sap.registerModulePath('Application', 'Application');
                jQuery.sap.require("Application");
                var oApp = new Application({
                    root : "content"
                });
        </script>
<link href="css/stylesheet.css" rel="stylesheet" type="text/css">

    </head>
    <body class="sapUiBody" role="application">
        <div id="content"></div>
    </body>
</html>

I am developing a sapui5 application in which I have a split app,now on the detail page in the toolbar I have a button called open in new window.So I want to open this particular detail page(only detail page) in a new tab on clicking this button.我正在开发一个sapui5应用程序,其中我有一个拆分应用程序,现在在工具栏的详细信息页面上,我有一个名为在新窗口中打开的按钮。所以我想在新选项卡中打开这个特定的详细信息页面(仅详细信息页面)单击此按钮时。
Can anyone help me on this as in how to go about it?任何人都可以帮助我解决这个问题吗?

Thanks in advance.提前致谢。

Regards,问候,
Shalini沙利尼

Use the SAP's Router API.使用 SAP 的路由器API。 Basically, define your router, routes, pattern and targets objects in your manifest.json file:基本上,在manifest.json文件中定义路由器、路由、模式和目标对象:

"sap.ui5": {
  "rootView": {
    "viewName": "path.to.view.name",
    "type": "XML",
    "async": true
  },
  "routing": {
    "config": {
      "routerClass": "sap.m.routing.Router",
      "viewType": "XML",
      "viewPath": "path.to.view",
      "controlId": "init",
      "controlAggregation": "pages",
      "async": true
    },
    "routes": {
      "init": {
        "pattern": "",
        "target": "init",
        "viewId": "vid_init"
      },
      "target_name": {
        "pattern": "url_parameter",
        "target": "target_name",
        "viewId": "vid_view_name"
      }
    },
    "targets": {
      "target_name": {
        "viewName": "view_name",
        "transition": "show"
      }
    }
  }
}

Assign a press event handler in your button's properties:在按钮的属性中分配按下事件处理程序:

<Button id="myButton" press=".onOpenNewWindow" />

In your view's controller write a code to handle your event.在您的视图控制器中编写一个代码来处理您的事件。 Example:例子:

onOpenNewWindow: funtion(oEvent){
  sap.ui.require([
    "sap/m/library"
  ], sapMLib => sapMLib.URLHelper.redirect("#/url_parameter", /*new window*/true));
},

Resources资源

Basically, you can open a new tab in JavaScript like this:基本上,您可以像这样在 JavaScript 中打开一个新选项卡:

window.open("<yourURL>", _blank');

For your SAPUI5 Application you simply have to provide an additional .html file at a dedicated URL which loads your View/Controller.对于您的 SAPUI5 应用程序,您只需在加载您的视图/控制器的专用 URL 处提供一个额外的.html文件。 If you want to pass information from the Master/Detail application to the new tab you could add URL parameters.如果您想将信息从 Master/Detail 应用程序传递到新选项卡,您可以添加 URL 参数。

As I can see in your edited question you´re using an Application.正如我在您编辑的问题中看到的那样,您正在使用应用程序。 I don´t know the further structure (especially what your Application.js does) but in a separate .html a very simple solution could look like this:我不知道进一步的结构(尤其是你的 Application.js 是做什么的),但在单独的.html一个非常简单的解决方案可能如下所示:

<script>
            sap.ui.localResources("views");
            sap.ui.localResources("i18n");
            sap.ui.localResources("utils");
            sap.ui.jsview("name.of.your.detailView").placeAt("content");
</script>

If you want to reuse your Application.js file you can extend it and pass a simple parameter which tells to display only one View.如果你想重用你的 Application.js 文件,你可以扩展它并传递一个简单的参数,它告诉只显示一个视图。

One more thing: I guess you´re using sap.m.SplitApp somewhere in your application.还有一件事:我猜您sap.m.SplitApp应用程序中的某个地方使用sap.m.SplitApp To display only the DetailView you should use sap.m.App instead at that point.要仅显示 DetailView,此时您应该使用sap.m.App

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

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