2013-05-05 85 views
0

我将要记下大量的笔记,如果我能够快速写入而不考虑格式化,我会学习最好的笔记。所以,我希望能够运行一个脚本来突出显示ListItems的不同部分,以便他们更容易重新阅读。我是新来的JavaScript,和Google应用程序脚本一样新。这里就是我这么远,并根据我的文档的理解,这应该工作...Google文档 - 突出显示列表文本

function highlightNotes() { 

    var doc = DocumentApp.getActiveDocument(); 
    var body = doc.getBody(); 
    var listItems = body.getListItems(); 

    for (var item in listItems){ 
    var item = body.getChild(item); 
    if (item.Attribute.NESTING_LEVEL == 0){ 
     item.Attribute.BACKGROUND_COLOR = "#FFFF00"; 
    } 
    } 
} 

而且,我的主要经验是蟒蛇,所以它可能是我只是在做一些错误假定语法。我得到的错误是:

TypeError: Cannot read property "NESTING_LEVEL" from undefined. 

我在做什么错了?

+0

为什么你不使用'getNestingLevel“的原因吗? https://developers.google.com/apps-script/reference/document/list-item#getNestingLevel() – 2013-05-05 00:40:24

+0

@ThomasOrozco很简单,因为我不知道它存在。虽然在你回应之前,我正在玩它,现在我想弄清楚如何改变背景颜色,因为我认为getNestingLevel修复了它。它会是listItems [item] .Attribute.BACKGROUND_COLOR =“#FFFF00”; ??? – jtsmith1287 2013-05-05 00:43:36

回答

0

我以为我被绝望地卡住了,但我想通了。

for (var item in listItems){ 
    var item = body.getChild(item); 
    if (item.getNestingLevel() == 0){ 
    item.asText().setBackgroundColor(#FFFF00"); 
    } 
} 

矣......没什么可看这里......