OK. This is the pattern that worked.
Main viewModel with the activatorlist:
glu.defModel('cpanel.VPCentreComponent', {
cmpList: {
mtype: 'activatorlist',
focusProperty: 'selectedCmp',
items: [{
mtype: 'DashboardCmp'
}, {
mtype: 'UsersCmp'
}, {
mtype: 'InvoicesCmp'
}]
},
selectedCmp: 0,
mainMenuButtonChange: function(newValue, oldValue, obj) {
// Use the key passed from the main menu item (newValue) to
// lookup the matching component (using it's viewmodelName for now).
// Return the matching component and set it to the selectedCmp property
// which will fire the relevant change event and make the matching
// viewModel (and it's associated view) the active one.
var cmp = this.cmpList.find(function(vm) {
return (vm.viewmodelName === newValue + "Cmp")
});
if (cmp) {
this.set('selectedCmp', cmp);
} else {
throw 'No matching view model for menu item key=' + newValue
}
}
});
It's view:
glu.defView('cpanel.VPCentreComponent', {
layout: 'card',
activeItem: '@{selectedCmp}',
items: '@{cmpList}'
});
With this the Dashboard panel, Users panel and Invoices panel becomes active as the user clicks the menu. All good. Not only that, amazingly simple implementation! Very cool.
Now, this might be obvious, but what is the best way for a viewModel to know it was just made the active one? I've tried various events and looked at the code but cant find something that works.
The reason I need it is that I don't want to load data from a server when the UsersCmp viewModel init() runs, I want to load it only when the user makes that viewModel active. They might never look at it and there is no reason to load the data if they don't need it.
Thanks,
Murray