2013-05-05 86 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"); 
    } 
} 

矣......沒什麼可看這裏......