Skip to Content
0

How to read js file data in ui5 controller

Oct 13, 2017 at 03:01 PM

31

avatar image
Former Member

Here is my constants.js file code , which contains the below data (static data).

var SORT_ORDER = {
    ASC : "ascending",
    DSC : "descending"
};
var YES = "yes";
var NO = "no";

i wanted to read this data in ui5 controller code.

sap.ui.define([
	'jquery.sap.global',		
	'sap/ui/core/mvc/Controller',
	'sap/ui/model/json/JSONModel',       
        "./constants"
], function (jQuery, Controller, JSONModel, constant) {
    "use strict";
    var PageController = Controller.extend("UI5Script.controller.Page1", {

        onInit: function () {
   
        var sortorder = constant.SORT_ORDER.ASC; // which throws error
},

 });
    return PageController;
});
10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

2 Answers

Best Answer
avatar image
Former Member
Oct 16, 2017 at 01:12 PM
0

Changing the path doesn't helps.

I found the solution by using the javascript "window" object

(function (window) {
    "use strict";  


    window.appConstants = {       
        YES: "yes",
        NO: "no"   
    };
}(window));

you can access the above constant in UI5 as shown below

appConstants.YES
Share
10 |10000 characters needed characters left characters exceeded
avatar image
Former Member Oct 13, 2017 at 05:58 PM
0


try

"UI5Script/constants" instead of

"./constants"

Share
10 |10000 characters needed characters left characters exceeded