5

This is very odd. This basic functionality does not work for some reason.

App controller:

    ({
    add : function(component, event, helper) {
        var items = component.get('v.obj')
        var subItem = {name:'three'}
        items.subItems.push( subItem )
        console.log(items.subItems.length)
        component.set( 'v.obj', items )
    },
    doInit: function(component, event, helper) {
         component.set( 'v.obj', {subItems:[{name:'one'}, {name:'two'}]}  )
    }
})

App:

<aura:application >
    <aura:attribute name="obj" type="Object"/>
    <aura:handler name="init" value="{!this}" action="{!c.doInit}"/>  
    <ui:button press="{!c.add}" label="add" />
</aura:application>

With locker enabled, console always prints 2. Without, it increments by one with each press.

Edit: I found that workaround. Turns out you need to get and set the subItem itself.

add : function(component, event, helper) {
        var items = component.get('v.obj.subItems')
        var subItem = {name:'three'}
        items.push( subItem )
        console.log(items.length)
        component.set( 'v.obj.subItems', items )
    }

This is fine enough for adding new items, but no idea how I could remove items in deeper nesting. Setting to undefined or {} does not help much.

1
  • I can reproduce the issue locally as well. This feels very similar to bugs we've encountered in the past, but appears to be slightly different. If you open a case with support you can reference bug ID W-3457602, which I just filed to track internally. Commented Nov 8, 2016 at 1:32

1 Answer 1

0

I'm not sure when exactly but this is fixed now.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .