How do I populate this checkbox with the data from an array in my controller?
My-view.js
function arrayBlock() {
return createModalBlock('Engage', [
{
type: 'section',
text: {
type: 'mrkdwn',
text: 'This is a section block with checkboxes.'
},
accessory: {
type: 'checkboxes',
options: [
{
text: {
type: 'mrkdwn',
text: 'Option 1'
},
description: {
type: 'mrkdwn',
text: 'user description'
},
value: 'value-0'
}
],
action_id: 'checkboxes-action'
}
}
], {
close: {
type: 'plain_text',
text: 'Close',
},
});
}
controller.js
arr = ["option 1", "option 2", "option 3", "option 4", "option 5"]
I can't copy your code, since you posted it as a Image
, but this is how you can do it:
arr = ["option 1", "option 2", "option 3", "option 4", "option 5"]
let arrayResult = arr.map((option, optionID) => {
return {
"text": {
"type": "mrkdwn",
"text": option
},
"description": {
"type": "mrkdwn",
"text": optionID
},
"value": `value-${optionID}`
}
})
console.log(arrayResult)
Using arr.map()
will solve your problem.