我想知道如何为这种类型的代码添加for循环。请忘记title, start, backgroundColor
和borderColor
值。我可以使用for循环加载它们。我想知道如何添加一个循环来打印这一切。
events: [
{
title: 'All Day Event',
start: new Date(y, m, 1),
backgroundColor: "#f56954", //red
borderColor: "#f56954" //red
},
{
title: 'Long Event',
start: new Date(y, m, d - 5),
end: new Date(y, m, d - 2),
backgroundColor: "#f39c12", //yellow
borderColor: "#f39c12" //yellow
},
{
title: 'Meeting',
start: new Date(y, m, d, 10, 30),
allDay: false,
backgroundColor: "#0073b7", //Blue
borderColor: "#0073b7" //Blue
},
{
title: 'Lunch',
start: new Date(y, m, d, 12, 0),
end: new Date(y, m, d, 14, 0),
allDay: false,
backgroundColor: "#00c0ef", //Info (aqua)
borderColor: "#00c0ef"//Info (aqua)
},
{
title: 'Birthday Party',
start: new Date(y, m, d + 1, 19, 0),
end: new Date(y, m, d + 1, 22, 30),
allDay: false,
backgroundColor: "#00a65a", //Success (green)
borderColor: "#00a65a" //Success (green)
},
{
title: 'Click for Google',
start: new Date(y, m, 28),
end: new Date(y, m, 29),
url: 'http://google.com/',
backgroundColor: "#3c8dbc", //Primary (light-blue)
borderColor: "#3c8dbc" //Primary (light-blue)
},
],
答案 0 :(得分:2)
如果你有所有元素的单独数组(title [],开始[],结束[]等..)那么你可以尝试下面这个
var main_array = [];
for (var i = 0; i < title.length; i++) {
main_array.push({
"title" : title[i],
"start" : start[i],
"end" : end[i],
"allDay" : allDay[i],
"backgroundColor" : backgroundColor[i],
"borderColor" : borderColor[i]
});
}