[SalesForce] Using a Map type attribute in aura:if

Trying to create a custom Navigation Bar and display menu entries based on user privileges.

I defined this attribute in my component:

<aura:attribute name="navItemPrivs" type="Map" default="{ Task: false }"/>

In the JS controller and helper I'm able to access and modify it using navItemPrivs['Task'], but when I try and use it inside an aura:if expression:

<aura:if isTrue="{!and(v.navItemLabel1 != undefined, v.navItemPrivs['Task'] == true}">

I get an error:

expecting a positive integer, found ''Task'' at column 50 of expression: and(v.navItemLabel1 != undefined, v.navItemPrivs['Task'] == true

I can't access it using v.navItemPrivs[0] because the "0" key isn't defined (nor do I want it to be).

Is there something I'm doing wrong and this isn't the way to do it? Because I don't see why I would not be able to access Map values if they exist in the framework..

Best Answer

You can access the attribute as v.navItemPrivs.Task and that should work just fine. Object properties are accessible by dot notation but not brackets unless they are integers.

Unfortunately you can't bind to dynamically named keys (e.g. you can't do v.myMap[v.myKey] in Lightning so far). Be aware that under the current way Locker functions (as of Summer '16 Patch 10.0) if you want a Map/Object key binding to be successful the key must exist when you first push the object to the v.attribute it will reside in.