这是创建数组的函数:
//retrieve calendar id's
function getCalendarId(){
gapi.client.load('calendar', 'v3', function() {
var request = gapi.client.calendar.calendarList.list();
request.execute(function(resp) {
var calendarID = [];
for (var i = 0; i < resp.items.length; i++) {
var ID = resp.items[i].id;
var calendarSummary = resp.items[i].summary;
var calendarLocation = resp.items[i].location;
var calendarDescription = resp.items[i].description;
if (calendarDescription && calendarDescription.indexOf("Resource Tracker") != -1) {
var index = calendarID.length;
calendarID[index] = ID;
}//endif
}//end for
console.log(typeof calendarID);
return calendarID;
});//end request.execute function(resp)
});//end client.load function
}//end getCalendarId
这是分配它的函数:
function submitEvents(numHorses){
var startdate = $("#from").val();
var enddate = $("#to").val();
var horsetypes = [];
var calid = [];
console.log(typeof(calid));
calid = getCalendarId();
console.log(typeof(calid));
for (i=0; i<numHorses;i++){
horsetypes[i] = $( "#type"+i).val();
addEvent(calid[i%calid.length], startdate, enddate, horsetypes[i]);
}//end for
};//end submitEvents
当我检查类型时, calendarID 在返回之前是一个对象,当我声明它时 calid 是一个对象,但是当我进行赋值时 calid=getCalendarID(); calid 的类型变得未定义。
我的头撞墙已经有一段时间了;任何帮助表示赞赏!