I can't find how to get all the todos of a calendar in Lightning. I thought the functions getItem()
and getItems()
from the calICalendar
Interface (here) were the solution but I could not make it work properly.
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
You are going in the right direction. You just need to pass the flag that you want todos only. An example can be found here.
To elaborate more on your example below, there are a few syntax errors and you might need different flags. I'm not sure why the alert is needed, that sounds to me like the event loop is not being spun. In what context are you calling these bits?
Try this:
var arrayItems = new Array();
var todoListener = {
onOperationComplete: function(aCalendar, aStatus, aOperationType, aId, aDetail) {},
onGetResult: function(aCalendar, aStatus, aItemType, aDetail, aCount, aItems) {
arrayItems = arrayItems.concat(aItems);
}
};
var filter = aCalendar.ITEM_FILTER_TYPE_TODO | aCalendar.ITEM_FILTER_COMPLETED_ALL;
aCalendar.getItems(filter, 0, null, null, todoListener);
回答2:
Thanks to your example, I understood how to implement the listener which was my main problem.
So here what I code :
var arrayItem = new Array; ;
var todoListener =
{
onOperationComplete: function(aCalendar, aStatus, aOperationType, aId, aDetail) {},
onGetResult: function(aCalendar, aStatus, aItemType, aDetail, aCount, aItems)
{
for (let i=0; i < aCount; i++)
{
arrayItem.push(aItems[i]);
}
}
};
var filter = aCalendar.ITEM_FILTER_ALL_ITEMS;
filter |= aCalendar.ITEM_FILTER_TYPE_TODO;
aCalendar.getItems(filter, 0, null, null, todoListener);
However, I have a really weird issue here. Actually, I do not get the todos with this code. I have to add an alert("something");
after the getItems() method to get my arrayItem filled up. Else, it is empty.