I have a requirment where i need to show some alert messages to the user. The alert message should be non blocking and if the user scrolls the page down, the alert should also move so that the user will always have the attention to it.
I looked at the showToast and saw that it serves the purpose what i need. However, the message which will be displaying will contain URLS. There can be 5 urls or 4 etc. Basically the URLs will be build dynamically.
I looked at the documentation and saw messageDataTemplate attribute with a label and URL but i am stuck as to how i can populate the message data template dynamically ?. It works if i manuyally hard code the URLS multiple or 3 but cannot figure out the dynamic part.
var dynamicMessage = 'Record {0} created! See it {1},{2}!'
var toastEvent = $A.get("e.force:showToast");
toastEvent.setParams({
"mode": "pester",
"type": "error",
"duration": "20000",
"message": "Test Error Message",
"messageTemplate": dynamicMessage,
"messageTemplateData": ['Salesforce', {
"url": 'http://www.salesforce.com/',
"label": 'hello',
},
{
"url": 'http://www.cnn.com/',
"label": 'foo',
}
]
});
toastEvent.fire();
what i want is the messageTemplateData to be created dynamically instead of me hardcoding. There can be 3 or 4 depending on how many aere stored in DB and what the controller will send me. Any help will be greatly appreciated
Update
THis does not work.
({
init : function(component, event, helper) {
var finalList = [];
for(var i=0; i<2; i++) {
console.log('Adding rows');
var answers = [];
answers.url = 'foo.com';
answers.label = 'hello';
finalList.push(answers);
}
console.log('final List ' + finalList.length);
var dynamicMessage = 'Record created! See it {1},{2}!'
var toastEvent = $A.get("e.force:showToast");
toastEvent.setParams({
"mode": "pester",
"type": "error",
"duration": "20000",
"message": "Test Error Message",
"messageTemplate": 'Record created! See it {0},{1}!',
"messageTemplateData": finalList
});
toastEvent.fire();
}