Having some problems dynamically creating a lightning:buttonMenu using $A.createComponents(). Creating the buttonMenu works fine but as soon as I try to add a lightning:menuItem I get the following when I click the menu:
error:
Uncaught Assertion Failed!: Descriptor for Config required for registration : undefined throws at ...
helper method from component:
createFilterMenu: function(cmp) {
var options = cmp.get('v.filterOptions')
var menuOptions = [
[
'lightning:buttonMenu', {
'aura:id': 'filterMenu',
'iconName': 'utility:filterList',
'alternativeText': 'Filter Selection',
'value': cmp.getReference('v.filter'),
'onselect': cmp.getReference('c.filterChange')
}
],
[
'lightning:menuItem',{
'label': 'test',
'value': 'test'
}
]
]
$A.createComponents(
menuOptions,
function(components, status, errorMessage) {
if (status === 'SUCCESS') {
var menuDiv = cmp.find('menu')
var menu = components[0]
var item = components[1]
menu.set('v.body',item)
menuDiv.set('v.body', menu)
} else if (status === 'INCOMPLETE') {
console.log('No response from server or client is offline.')
} else if (status === 'ERROR') {
console.log('Error: ' + errorMessage)
}
}
)
}
Best Answer
Please refer to http://dfyjkt.blogspot.com/2018/09/is-it-impossible-to-dynamically.html
The reason is buttonMenu's body is Aura.ComponentDefRef, not the usual Aura.Component. The workaround in that post does not work for me, but it explains why it does not work.