我正在尝试从Google日历中获取一些json数据并将其输入到名为“Simple Events Calendar”的jquery插件中
插件需要这样的东西:
var events_array = new Array(
{
startDate: new Date(2014,02,12,17,30),
endDate: new Date(2014,02,12,18,0),
title: 'eventName',
description: 'eventSummary',
priority: 3, // 1 = Low, 2 = Medium, 3 = Urgent
frequency: 1 // 1 = Daily, 2 = Weekly, 3 = Monthly, 4 = Yearly
},
{
startDate: new Date(2014,02,10,20,50),
endDate: new Date(2014,02,10,20,59),
title: "Event 2",
description: "Description 2",
priority: 1,
frequency:1
},
{
startDate: new Date(2014,07,20,18,0),
endDate: new Date(2014,00,20,21,30),
title: "Event 3",
description: "Description 3",
priority: 3,
frequency:1
}
);
我抓住并解析这样的数据:
var urllist = ["http://www.google.com/calendar/feeds/events%40wilsonabbey.com/public/full? orderby=starttime&sortorder=ascending&max-results=3&futureevents=true&alt=json"];
var JSONData = { count: 0,
value : {
description: "Wilson Abbey Events",
generator: "StackOverflow communal coding",
items: []
}};
urllist.forEach(function addFeed(url){
$.getJSON(url, complete);
});
function complete(result, status, jqXHR) {
var eventName = [];
var eventSummary = [];
var data_element = '';
var events_array = new Array();
// Track the number of calls completed back, we're not done until all 3
// asynchronous calls have returned
if( typeof complete.count === 'undefined' )
complete.count = urllist.length;
if(!result.feed.entry) {
console.log("No entries from ");
} else {
JSONData.count += result.feed.entry.length;
JSONData.value.items = JSONData.value.items.concat(result.feed.entry);
}
//console.log(complete.count);
if (!(--complete.count)) {
console.log(JSONData);
var str = "";
for (var i = 0; i < JSONData.value.items.length; i++) {
var item = JSONData.value.items[i];
str += item.author[0].name.$t + " (starts " + item.gd$when[0].startTime + "): " + item.title.$t + "\n";
eventName[i] = item.title.$t;
eventSummary[i] = item.content.$t;
dataItem = 'startDate: new Date(2014,02,12,17,30),';
dataItem += 'endDate: new Date(2014,02,12,18,0),';
dataItem += 'title: ' + eventName[i] + ',';
dataItem += 'description: ' + eventSummary[i] + ',';
dataItem += 'priority: 3,';
dataItem += 'frequency: 1';
events_array[i] = dataItem;
}
console.log(events_array);
$("#calendar").dp_calendar({
events_array: events_array
});
}
}
大多数代码都是由社区提供的,主要是问题我 我正在将数据放入简单事件日历将接受的格式。
感谢您的任何建议!
Rick Mills
但我收到错误(来自控制台) 未捕获的TypeError:无法调用未定义的方法'getHours'
答案 0 :(得分:0)
想出来 - 我需要创建一个对象数组,我正在创建一个字符串文字数组。
在for循环中替换了新代码:
var obj = {
startDate: new Date(2014,02,14,17,30),
endDate: new Date(2014,02,14,18,0),
title: item.title.$t,
description: 'eventSummary',
priority: 3, // 1 = Low, 2 = Medium, 3 = Urgent
frequency: 1 // 1 = Daily, 2 = Weekly, 3 = Monthly, 4 = Yearly
};
events_array.push(obj);