打开 Bootbox 警报 - 循环遍历字符串数组并显示复选框列表
Open Bootbox alert - Loop through array of strings and display check box list
我正在打开一个引导框警报,其中包含一个复选框列表,如下所示:
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);
}
});
我正在打开一个引导框警报,其中包含一个复选框列表,如下所示:
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);
}
});