on 07-07-2015 5:43 PM
Hi Community,
Here is my config.js
I am buillding a little rolecontrol here. My problem is, that i can't ready my JSON Objects right. i dont.
The weird point is, that when ever I try my code in the Browserconsole it works. When i use it in my actual Code, it always gives me undiefined, null or an empty Object (Object {} ).
Here is my Code:
Index.html
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta http-equiv='Content-Type' content='text/html;charset=UTF-8'/>
<script id="sap-ui-bootstrap" type="text/javascript"
src="resources/sap-ui-core.js"
data-sap-ui-theme="sap_bluecrystal"
data-sap-ui-xx-bindingSyntax="complex"
data-sap-ui-libs="sap.m,sap.ui.layout, sap.ui.commons, sap.ui.table">
</script>
<script src="config/config.js" type="text/javascript" ></script>
<script>
sap.ui.localResources("view");
var app = new sap.m.App("RootView",{initialPage:"MainPage"});;
var page1 = sap.ui.view({id:"MainPage", viewName:"view.entry", type:sap.ui.core.mvc.ViewType.JS});
var page2 = sap.ui.view({id:"Logbook", viewName:"view.Logbook.Logbook", type:sap.ui.core.mvc.ViewType.JS});
var profileModel = new sap.ui.model.json.JSONModel("model/getCurrentProfile.json");
sap.ui.getCore().setModel(profileModel, "profile");
setRole();
app.addPage(page1).addPage(page2);
app.placeAt("content");
</script>
</head>
<body class="sapUiBody" role="application">
<div id="content"></div>
</body>
</html>
//Configuration
jQuery.sap.declare("main.app.config");
jQuery.sap.require("sap.ui.model.json.JSONModel");
main.app.config = {
visible : false
};
function setRole() {
pModel = sap.ui.getCore().getModel("profile")
console.log("pModel BELOW");
console.log(pModel);
console.log("________________________");
console.log("pModel.getData() BELOW");
console.log(pModel.getData());
console.log("________________________");
// switch (pModel.oData[0].role) {
// case "admin":
// break;
// case "user"://
// break;
// case "user2":
// break;
// default:
// }
}
And my JSON file:
[
{
"firstname": "Mister",
"lastname": "Test",
"email": "test@mail.de",
"language": "en",
"role": "admin"
}
]
In the Screenshots I will show this, for me, unexplainable behavouir:
I hope some of you have an Idea why this is not working.
Regards,
Dain
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
So far that help really good, thank you!
But now I'm facing a new issuse.
I wanted to set this whole thing up, to get global models, to use them in every controller or view i got in my solution.
when I now trie to use
sap.ui.getCore().getModel("profile")
in a diffrent view, its always undefined.
I found out that the Problem is, that CreateContet() is called before attachRequestCompleted().
Do you have any examples or tips of how I can set global Model?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.