Je veux saisir le UserName

session["user"].name ou session["user:name"] ?

//put user session in to js global space :(
var session = {
    user: {
        "Id":"d675cb62-f635-407e-7b5e-02269cfd0a66",
        "Name":"arten, Rod",
        "PrincipalName":"CN=rmarten,OU=Standard Users,OU=Internal,OU=ade People,DC=bae,DC=ade",
        "UserName":"arten",
        "Domain":"baD",
        "Email":null,
        "Company":"blah",
        "Title":"FIELD SERVICES DIRECTOR",
        "FirstName":"ARod",
        "LastName":"arten",
        "EmployeeId":"44496",
        "Analyst":1,
        "AssetManager":1,
        "LicenseExpires":"\/Date(253402300799999)\/",
        "KnowledgeManager":1,
        "IsAdmin":false
}};
-4
Chad Jacobs 16 mars 2019 à 01:30

2 réponses

Meilleure réponse

Vérifier la console

 var session = {
  user: {"Id":"d675cb62-f635-407e-7b5e-02269cfd0a66","Name":"arten, Rod","PrincipalName":"CN=rmarten,OU=Standard Users,OU=Internal,OU=ade People,DC=bae,DC=ade","UserName":"arten","Domain":"baD","Email":null,"Company":"blah","Title":"FIELD SERVICES DIRECTOR","FirstName":"ARod","LastName":"arten","EmployeeId":"44496","Analyst":1,"AssetManager":1,"LicenseExpires":"\/Date(253402300799999)\/","KnowledgeManager":1,"IsAdmin":false,"Security":{"CanCreateIncident":true,"CanCreateServiceRequest":true,"CanCreateChangeRequest":false,"CanCreateProblem":true,"CanCreateReleaseRecord":true,"CanEditManualActivity":true}}
 }

console.log(session.user.UserName)
1
fatema 15 mars 2019 à 22:36

Une alternative consiste à utiliser Affectation de déstructuration

var session = {
  user: {"Id":"d675cb62-f635-407e-7b5e-02269cfd0a66","Name":"arten, Rod","PrincipalName":"CN=rmarten,OU=Standard Users,OU=Internal,OU=ade People,DC=bae,DC=ade","UserName":"arten","Domain":"baD","Email":null,"Company":"blah","Title":"FIELD SERVICES DIRECTOR","FirstName":"ARod","LastName":"arten","EmployeeId":"44496","Analyst":1,"AssetManager":1,"LicenseExpires":"\/Date(253402300799999)\/","KnowledgeManager":1,"IsAdmin":false,"Security":{"CanCreateIncident":true,"CanCreateServiceRequest":true,"CanCreateChangeRequest":false,"CanCreateProblem":true,"CanCreateReleaseRecord":true,"CanEditManualActivity":true}}
 }

let {user:{UserName}} = session

console.log(UserName)
0
Code Maniac 16 mars 2019 à 03:10