如何替换已弃用的 jQuery 函数?
How to replace deprecated jQuery functions?
我正在尝试使用 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);
},
我应该如何替换已弃用的功能?我应该在哪里添加新代码?
如果您现在查看 jQuery.sap.encodeURL
, you see it states to use the module sap/base/security/encodeURL
的 API 文档。
文档中的用法示例:
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;
}
};
});
我正在尝试使用 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);
},
我应该如何替换已弃用的功能?我应该在哪里添加新代码?
如果您现在查看 jQuery.sap.encodeURL
, you see it states to use the module sap/base/security/encodeURL
的 API 文档。
文档中的用法示例:
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;
}
};
});