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.