“未捕获的TypeError:sap.ui.require.toUrl不是函数”

时间:2019-06-21 05:52:25

标签: sapui5

我尝试学习Fiori时发生错误。任何帮助将不胜感激。

onInit中,它表示:

  

未捕获的TypeError:sap.ui.require.toUrl不是函数。

sap.ui.define([
  "sap/ui/core/mvc/Controller",
  // ...
], function(Controller /*...*/) {
  "use strict";

  return Controller.extend("Upload_TestUpload_Test.controller.View1", {
    onInit: function() {
      var sPath = sap.ui.require.toUrl("Upload_Test/uploadCollection.json");
      this.getView().setModel(new JSONModel(sPath));
    },

    // ...

  });
});

Sap UI版本:“ 1.52.12”

1 个答案:

答案 0 :(得分:0)

var sPath = sap.ui.require.toUrl("Upload_Test/uploadCollection.json");
           

Sap UI版本:“ 1.52.12”

API sap.ui.require.toUrl仅在 1.58.0 起可用。如果无法更新UI5,则必须使用API​​ jQuery.sap.getResourcePath

sap.ui.define([
  "sap/ui/core/mvc/Controller",
  "jquery.sap.global",
  // ...
], function(Controller, jQuery /*...*/) {
  "use strict";

  return Controller.extend("...", {
    onInit: function() {
      var sPath = jQuery.sap.getResourcePath("Upload_Test/uploadCollection.json");  // Use sap.ui.require.toUrl from UI5 1.58. The jQuery API is deprecated!
      this.getView().setModel(new JSONModel(sPath));
      // ...
    },

    // ...
  });
});

API reference: jQuery.sap.getResourcePath