简体   繁体   English

如何在 SAPUI5 中的表列上创建链接

[英]How to create links on the column of table in SAPUI5

Could anyone please give me some idea how to create links on table column contents (only for two columns) and this contents are coming from ODATA service and after pressing any content it should go to the particular link?任何人都可以给我一些想法如何在表格列内容上创建链接(仅适用于两列),这些内容来自ODATA服务,按下任何内容后,它应该转到特定链接?

Ex.前任。 Suppose the every table content has {mainUrl} and假设每个表的内容都有 {mainUrl} 和

For 1st column: Deep Link: /bb/ccc/eee?reqid = Example URL: {mainUrl}/bb/ccc/eee?reqid=6000对于第一列:深层链接:/bb/ccc/eee?reqid = 示例 URL:{mainUrl}/bb/ccc/eee?reqid=6000

For 2nd column: Deep Link: /bb/cc/fff?jobid= Example: {mainUrl}/bb/cc/fff?jobid=4000对于第二列:深层链接:/bb/cc/fff?jobid= 示例:{mainUrl}/bb/cc/fff?jobid=4000

I tried couple of the examples: ex-1 , ex-2 .我尝试了几个例子: ex-1ex-2 But I'm not sure how to fix it for this case.但我不确定如何解决这种情况。 I'd really appreciate if you could provide me some example codes if it's possible.如果可能的话,如果您能给我提供一些示例代码,我将不胜感激。

Thanks in advance.提前致谢。

A simple example how to create links on table columns is based on Link - Subtle example.如何在表列上创建链接的简单示例基于Link - Subtle示例。

  1. In the /mockdata/products.json for each 'ProductPicUrl' field value remove a host name 'https://openui5.hana.ondemand.com' .在每个 'ProductPicUrl' 字段值的 /mockdata/products.json 中删除主机名'https://openui5.hana.ondemand.com'

  2. As a result the link in the column has got a host of the dev server, eg is 'http://localhost:8081/test-resources/sap/ui/documentation/sdk/images/HT-2001.jpg'结果列中的链接有一个开发服务器的主机,例如是'http://localhost:8081/test-resources/sap/ui/documentation/sdk/images/HT-2001.jpg'

  3. In the Link.view.xml view change the first column content by adding a formatter function see Walkthrough Step 22: Custom Formatters :在 Link.view.xml 视图中,通过添加格式化程序函数来更改第一列内容,请参见演练步骤 22:自定义格式化程序

     <ColumnListItem> <Link text="{Name}" href="{ path: 'ProductPicUrl', formatter: '.hrefFormatter' }" />
  4. And implement the formatter in the Link.view.xml controller file:并在 Link.view.xml 控制器文件中实现格式化程序:

     hrefFormatter: function(sUrl) { var mainUrl = 'https://openui5.hana.ondemand.com'; return mainUrl + sUrl; }
  5. Using the formatter provides modified link URL: 'https://openui5.hana.ondemand.com/test-resources/sap/ui/documentation/sdk/images/HT-1002.jpg'使用格式化程序提供修改后的链接 URL: 'https://openui5.hana.ondemand.com/test-resources/sap/ui/documentation/sdk/images/HT-1002.jpg' : 'https://openui5.hana.ondemand.com/test-resources/sap/ui/documentation/sdk/images/HT-1002.jpg'

I've solved this by writing the codes in JS file:我通过在 JS 文件中编写代码解决了这个问题:

createAllColumns: function () {
.....
.....
 var oTemplate = new Text({
                        text: sText,
                        wrapping: false
                    }); // for default columns

                    if (oChar.charId === "columnID") {
                        oTemplate = new Link({
                            text: sText,
                            press: this.readTheID
                        });
                    }
......
......
},

readTheID: function (oEvent) {
            const oBind = oEvent.getSource().getParent().getBindingContext("service name");
            const obj = oBind.getObject().columnID;
            const value = oEvent.getSource().getProperty("text");

            return models.getInstance().getOdataWrapper().getEntitySet({
                path: "/OdataServiceEntitySet",
                filters: [new Filter({ path: "name", operator: FilterOperator.EQ, value1: "mainUrl" }),
                new Filter({ path: "columnID", operator: FilterOperator.EQ, value1: obj })],
                And: true
            }).then((odata) => {
                if (odata.length > 0) {
                    var mainLink = odata[0].getObject().value;
                    sap.ui.require([
                        "sap/m/library"
                    ], sapMLib => sapMLib.URLHelper.redirect(mainLink + "/bb/ccc/eee?reqid=" + value, /*new window*/true));
                }
            }).catch((err) => {
                sap.m.MessageToast.show("Failed");
            });

        },
 

Note : "sap/m/Link" produces dynamic links.注意:“sap/m/Link”产生动态链接。 In that case we can't reserve the links into the column contents, that's why user can't copy the link directly from the content.在这种情况下,我们无法将链接保留到列内容中,这就是用户无法直接从内容中复制链接的原因。

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

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