Javascript “保持获取未定义的对象”不是“我的桌面”上的对象(计算日期.substr';)错误

Javascript “保持获取未定义的对象”不是“我的桌面”上的对象(计算日期.substr';)错误,javascript,coffeescript,widget,Javascript,Coffeescript,Widget,大家好,我需要帮助。所以我使用了一个叫做Ubersicht的工具。它允许您使用.coffee脚本文件在Mac桌面上创建小部件。出现错误的应该是一个日历,用于显示即将发生的事件。这是它的代码 # Bash command to pull events from icalBuddy # Set +2 to how many days you want to show # icalBuddy has more functionality that can be used here command: "

大家好,我需要帮助。所以我使用了一个叫做Ubersicht的工具。它允许您使用.coffee脚本文件在Mac桌面上创建小部件。出现错误的应该是一个日历,用于显示即将发生的事件。这是它的代码

# Bash command to pull events from icalBuddy
# Set +2 to how many days you want to show
# icalBuddy has more functionality that can be used here
command: "/usr/local/bin/icalBuddy -n eventsToday+2"

# Update is called once per hour
refreshFrequency: "1h"

# CSS styling
style: """
top: 10px
top: 35%
right: 73.5%
color: black
font-family: SF UI Text
background-color rgba(white, 0.2)
padding 15px
border-radius 5px
width: 270px

div
    display: block
    color white
    font-size: 14px
    font-weight: 450
    text-align left

#head
    font-weight: bold
    font-size 20px

#subhead
    font-weight: bold
    font-size 16px
    border-bottom solid 1px clear
    padding-top 6px
    padding-bottom 3px
    """

 # Initial render for heading
 render: (output) -> """
<div id="head"> Upcoming Events </div>
"""

# Update when refresh occurs
update: (output, domEl) ->
lines = output.split('\n')
bullet = lines[0][0]
newarray = []

# Copy lines to new array, ignoring all location lines
# This allows for easier tokenizing as array format is consistent
for line in lines
    if ( line.indexOf("location") == -1 )
        newarray.push(line)

# Check that events actually exist or not
if ( lines.length < 2 )
    if ($(domEl).text().indexOf("No Events") == -1)
        $(domEl).append(""" <div id="subhead"> No Events </div> """)
    return

# If events exist, print subheadings and data
for i in [0...newarray.length-2]

    # Print today subheading
    if ( newarray[i+1].indexOf("today") != -1 )
        if ($(domEl).text().indexOf('Today') == -1)
            $(domEl).append("""<div id="subhead"> Today </div> """)
    # Print tomorrow subheading
    else if ( newarray[i+1].indexOf("tomorrow") != -1 )
        if ($(domEl).text().indexOf('Tomorrow') == -1)
            $(domEl).append(""" <div id="subhead"> Tomorrow </div> """)
    # Print later subheading
    else if ( newarray[i+1].indexOf("after") != -1 )
        if ($(domEl).text().indexOf('Day After Tomorrow') == -1)
            $(domEl).append(""" <div id="subhead"> Day After Tomorrow </div>     """)
    # Only print event newarray, starting with a bullet point
     if (newarray[i][0] == bullet)
        # Tokenize icalBuddy output string
        name_and_calendar = newarray[i].split('(')
        name = name_and_calendar[0].substr(1)
        # Trim length of name field
        if ( name.length > 25 )
            name = name.substr(0,25) + "..."
        # Trim date and format output
        if ( ':' in newarray[i+1] )
            date = ((newarray[i+1].split("at"))[1])
            date = "at" + date.substr(0,9)
        # If its an allday event, date field is empty
        else
            date = ""
        # Cleanse output from icalBuddy
        calendar = name_and_calendar[1].replace(')','')
        # Combine all fields
        final = calendar + " - " + name + date

        # Add this HTML to previous, only if it doesn't already exist
        if ($(domEl).text().indexOf(final) == -1)
            $(domEl).append("""
            <div>
                #{final}
            </div>
            """)
#从icalBuddy中提取事件的Bash命令
#将+2设置为要显示的天数
#icalBuddy具有更多可在此处使用的功能
命令:“/usr/local/bin/icalBuddy-n eventsToday+2”
#更新每小时调用一次
刷新频率:“1h”
#CSS样式
样式:“
顶部:10px
最高:35%
右:73.5%
颜色:黑色
字体系列:SF UI文本
背景色rgba(白色,0.2)
填充15px
边界半径5px
宽度:270px
div
显示:块
白色
字号:14px
字号:450
文本左对齐
#头
字体大小:粗体
字体大小20px
#分目
字体大小:粗体
字体大小16px
边框底部实心1px透明
填充顶部6px
垫底3件
"""
#标题的初始渲染
渲染:(输出)->“”
即将举行的活动
"""
#发生刷新时更新
更新:(输出,圆顶)->
行=输出。拆分('\n')
项目符号=行[0][0]
newarray=[]
#将行复制到新阵列,忽略所有位置行
#由于数组格式是一致的,这使得标记化更容易
排队
if(第行索引(“位置”)=-1)
newarray.push(行)
#检查事件是否确实存在
如果(线长度<2)
if($(domEl).text().indexOf(“无事件”)=-1)
$(domEl.append(““无事件”)
返回
#如果存在事件,打印副标题和数据
对于[0…newarray.length-2]中的i
#今日列印副标题
if(newarray[i+1].indexOf(“今天”)!=-1)
if($(domEl.text().indexOf('Today')=-1)
$(domEl)。追加(““今天”)
#明天列印副标题
else if(newarray[i+1].indexOf(“明天”)!=-1)
if($(domEl).text().indexOf('tomory')=-1)
$(domEl)。追加(““明天”)
#稍后列印副标题
else if(newarray[i+1].indexOf(“after”)!=-1)
if($(domEl.text().indexOf('后天')=-1)
$(domEl)。追加(““后天”)
#仅打印事件newarray,以项目符号开头
if(newarray[i][0]==项目符号)
#标记化icalBuddy输出字符串
name_and_calendar=newarray[i]。拆分(“(”)
名称=名称和日历[0]。子字符串(1)
#修剪名称字段的长度
如果(name.length>25)
name=name.substr(0,25)+“…”
#修剪日期和格式输出
if(':'在newarray[i+1]中)
日期=((新数组[i+1]。拆分(“at”))[1])
date=“at”+日期子项(0,9)
#如果是全天事件,则日期字段为空
其他的
date=“”
#清除icalBuddy的输出
日历=名称和日历[1]。替换('),“”)
#合并所有字段
最终=日历+“-”+姓名+日期
#仅当此HTML不存在时,才将其添加到上一个HTML
if($(domEl).text().indexOf(final)=-1)
$(domEl.append(“”)
#{final}
""")

任何帮助都将不胜感激

是否
date=((newarray[i+1].split(“at”))[1])
未定义的
,因为
newarray[i+1]
不包含
“at”
?@le_m可能。那么我该怎么做才能修复它呢?不知道,这取决于
newarray
的内容,以及如果它在“处不包含
”您想做什么。