简体   繁体   中英

Get username for SAPUI5 in WebIDE

This is probably just some easy JavaScript code i can't figure out, but i am trying to get the username of currently logged in user. Or this is an oData concept, which i am not familiar with. Here is the code for retrieving it:

onComment: function (oEvent) 
    {
        //gets username
        var userModel = new sap.ui.model.json.JSONModel("/services/userapi/currentUser");
        var username = userModel;
     console.log(username);
    }

I know something is supposed to go after the var username = userModel but i cannot get the correct output. Here is what i am getting in the console

constructor {pSequentialImportCompleted: Promise, mEventRegistry: Object, mMessages: null, id: "id-1501515372158-22", oData: Object…}

oData: Object

+displayName:"Tyler Genio (Sxxxxxxxx)"

+email:"tyler.i.Genio@company.com"

+firstName:"Tyler"

+lastName:"Genio"

+name: "Sxxxxxxxx"

How do i get the first and last name out of that? I've see a few articles online that talk about it, but some of it goes over my head. Sorry for any confusion about the coding format on here.

if your model is structured as stated, ie

{
    "displayName": "Tyler Genio (Sxxxxxxxx)",
    "email": "tyler.i.Genio@company.com",
    "firstName": "Tyler",
    "lastName": "Genio",
    "name": "Sxxxxxxxx"
}

then userModel.getProperty("/name");

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM