gpt4 book ai didi

javascript - 将 FullCalendar 事件填充为数组 - 从另一个数组填充

转载 作者:行者123 更新时间:2023-11-29 15:01:40 24 4
gpt4 key购买 nike

我对 JS 很陌生。我对 Web 服务的调用返回如下数组:

data {...}
[0]: {...}
[1]: {...}
[2]: {...}
[3]: {...}
length: 4

data[0] {...}
__type: "acme.acmeSystem.EventManagement.Event"
Amenity: {...}
DateFrom: "/Date(1326952800000)/"
DateTo: "/Date(1326952800000)/"
Description: "Friends coming over for a party."
Food: false
Id: 3
IsPrivate: true
Notes: ""
NumberOfPeople: "Less than 10"
Status: {...}
TimeFrom: "8:30 AM"
TimeTo: "11:30 AM"
User: {...}

如何将其插入 FullCalendar?

我正在尝试这样的事情:

GetEvents([], false,
{
successCallback: function (data) {
if ((data) && (data != null) && (data.length > 0)) {

buildingEvents = data;

$('#calendar').fullCalendar({
theme: true,
header: {
left: 'prev,next today',
center: 'title',
right: 'month,agendaWeek,agendaDay'
},
editable: false,
events: buildingEvents
});

}

data = null;
}
});

我需要从构建事件数组创建另一个 FullCalendar 事件数组:

类似于:

$('#calendar').fullCalendar({
events: [
{
title : 'event1',
start : '2010-01-01'
},
{
title : 'event2',
start : '2010-01-05',
end : '2010-01-07'
},
{
title : 'event3',
start : '2010-01-09 12:30:00',
allDay : false // will make the time show
}
]
});

谢谢。

最佳答案

嗯,我猜你可以使用 jquery 函数 $.map() .

jQuery.map( array, callback(elementOfArray, indexInArray) ) Returns: Array
Description: Translate all items in an array or object to new array of items.

基本上,您将从服务器接收到的数据映射到 fullCalendar 可以理解的 EventData 对象数组中:

var buildingEvents = $.map(data, function(item) {
return {
id: item.Id,
title: item.Description,
start: ... // "bind" all properties as needed
};
});

关于javascript - 将 FullCalendar 事件填充为数组 - 从另一个数组填充,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9168147/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com