【问题标题】:How to replace deprecated jQuery functions?如何替换已弃用的 jQuery 函数?
【发布时间】:2020-08-31 09:32:04
【问题描述】:

我正在尝试使用 formatter.js 在我的 UI5 应用中显示地图,我需要将地址与地图 URL 放在一起。
在旧世界中,代码应如下所示:

formatMapUrl: function(sStreet, sZIP, sCity, sCountry) {
  return "https://maps.googleapis.com/maps/api/staticmap?zoom=13&size=640x640&markers="
    + jQuery.sap.encodeURL(sStreet + ", " + sZIP +  " " + sCity + ", " + sCountry);
},

我应该如何替换已弃用的功能?我应该在哪里添加新代码?

【问题讨论】:

    标签: sapui5 amd


    【解决方案1】:

    如果您查看 jQuery.sap.encodeURL 的 API 文档,您会看到它声明现在使用模块 sap/base/security/encodeURL

    文档中的使用示例:

    sap.ui.require(["sap/base/security/encodeURL"], function(encodeURL) {
       var sEncoded = encodeURL("a/b?c=d&e");
       console.log(sEncoded); // a%2fb%3fc%3dd%26e
    });
    

    formatter.js 中的用法:

    sap.ui.define([
      "sap/base/security/encodeURL"
    ], function (encodeURL) {
      "use strict";
    
      return {
        formatMapUrl: function(sStreet, sZIP, sCity, sCountry) {
          var sBaseUrl = "https://maps.googleapis.com/maps/api/staticmap?zoom=13&size=640x640&markers=";
          var sEncodedString = encodeURL(sStreet + ", " + sZIP +  " " + sCity + ", " + sCountry);
          return sBaseUrl + sEncodedString;
        }
      };
    });
    

    【讨论】:

      猜你喜欢
      • 2019-12-20
      • 2020-10-22
      • 1970-01-01
      • 2013-05-08
      • 2016-10-15
      • 2020-02-27
      • 2013-01-13
      • 2013-04-17
      • 1970-01-01
      相关资源
      最近更新 更多