cancel
Showing results for 
Search instead for 
Did you mean: 

Setting a JSON Model value in a JavaScript Variable

Former Member
0 Kudos

Hi fórum

I have a SAP UI5 XML View that show the value of a Json Model .... in a Text Component

<Text xmlns="sap.m" id="iduser" text="{userapi>/displayName}"></text>

That´s work fine, but I want to setting the value of {userapi>/displayName} in a JavaScript Variable... how can i do that ?


In the "index.html" i have the next code... and in this part i need the JavaScript Variable with the value of "displayname".

var userModel = new sap.ui.model.json.JSONMODEL("/services/userapi/currentUser");

sap.ui.getCore.setModel(userModel, "userapi");

Thanks

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

hi Josue,

     Try


     var sDisplayName = sap.ui.getCore.getModel("userapi").getData().displayName;

Regards

Aasif Shah

Former Member
0 Kudos

Hi,

I have two question relating to the currentUser

  • Except for name and displayName, rest of the fields are blank. Where could be the issue? I need other fields such as email, firstName, lastName, etc.
  • I want to filter the table data with the logged in user but although it shows the value on the UI control, it is empty within the lifecycle funtions(onInit, onBeforeRendering, onAfterRendering ) of the view.

Thanks in advance!

Cheers

Jayant

Answers (2)

Answers (2)

former_member182862
Active Contributor
0 Kudos

Hi Josue

I believe this will work.

var userModel = new sap.ui.model.json.JSONModel("/services/userapi/currentUser");
userModel.attachRequestCompleted(function() {
   this.setProperty('/displayName', 'Me');
});
sap.ui.getCore().setModel(userModel, "userapi");

Thanks

-D

former_member182372
Active Contributor
0 Kudos

var userModel = new sap.ui.model.json.JSONMODEL({ displayName : "Josue" });