How to check for empty event.description (Google Calendar Feed)?

社会主义新天地 提交于 2019-12-25 07:59:41

问题


I'm using the latest version of FullCalendar and I was hoping someone could tell me how I could check whether an event got a description.

I tried it with this snippet, but the only thing I get is "undefined".

eventRender: function(event, element, view) {
    if(event.description == ''){var getDesc = event.description;};
    //some more code
},

I hope someone can help me. Thanks


I forgot to mention, that I use a google calendar feed to get events into my FullCalendar. When I use event.Description or event.Location or anything else that isn't set in my google events, I receive "undefined" as mentioned above.

Thanks to @Bryce Siedschlaw for pointing out my mistake to set getDesc only when the description is empty. That of course was not wanted. He also gave me some pretty good tips but sadly didn't work out for me.

If it's helping, here is a link to the FullCalendar I've set up, maybe it helps to understand what I'm saying. FullCalendar Setup

Ps. It isn't a beauty (and in german) but I'm working on it ;)


Found an answer after hours of research. @brasofilo answered it over there. Link to the solution.

var getDesc = (event.description) ? event.description : 'No Description';

It will check if the description is set and will output a default text if it isn't.


回答1:


There are a few things wrong with your code. First, you are initializing your getDesc variable inside the if statement, which, unless I'm wrong, will make it undefined when you try to access it later on in your eventRender function.

You should add var getDesc; above the if condition and remove the semi-colon from after the condition.

Next, you're attempting to set getDesc only when the description is empty. If you want to only set getDesc if there is a value in event.description, then I think you may have wanted to do something like this:

var getDesc = ""; // Change this to your own default value
if (event.description) { getDesc = event.description }
...

Otherwise, if you only want to set it when it's empty, then you could do something like this:

var getDesc = ""; // Change this to your own default value
if (event.description === "") { getDesc = event.description }
...

Let me know if that doesn't answer your question.



来源:https://stackoverflow.com/questions/28784629/how-to-check-for-empty-event-description-google-calendar-feed

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!