on 10-13-2017 4:01 PM
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;
});
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
try
"UI5Script/constants" instead of
"./constants"
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
84 | |
24 | |
11 | |
9 | |
7 | |
6 | |
5 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.