我正在打开一个启动箱警报,其中包含一个如下所示的复选框列表:
bootbox.prompt({
title: "This is a prompt with a set of radio inputs!",
message: '<p>Please select an option below:</p>',
inputType: 'radio',
inputOptions: [
{
text: 'Choice One',
value: '1',
},
{
text: 'Choice Two',
value: '2',
},
{
text: 'Choice Three',
value: '3',
}
],
callback: function (result) {
console.log(result);
}
});
这将打开一个带有3个选项的复选框列表的提示
我如何代替硬编码设置选项,我想遍历字符串数组并设置输入选项。我尝试在输入选项中添加一个for循环,但是此错误仅包含其中的标记。
这是我尝试过的:
var data = response.Data;
bootbox.prompt({
title: "This is a prompt with a set of radio inputs!",
message: '<p>Please select an option below:</p>',
inputType: 'radio',
inputOptions:
for(var i = 0; i<data.length; i++) {
[{
text: data[i],
value: data[i]
}]
}
callback: function (result) {
console.log(result);
}
});
var myCheckboxesArray = [];
var data = [1,2,3,4,5,6];
for(var i = 0; i<data.length; i++) {
myCheckboxesArray.push({text: 'Choice '+data[i],value: data[i]})
}
bootbox.prompt({
title: "This is a prompt with a set of checkbox inputs!",
value: ['1', '3'],
inputType: 'checkbox',
inputOptions: myCheckboxesArray,
callback: function (result) {
console.log(result);
}
});