You need to enable JavaScript to run this app. 如何修改代码获取OneNote页面NoteTags属性并清除已勾选的ToDo标签
优惠活动
大模型
产品
解决方案
定价
更多

如何修改代码获取OneNote页面NoteTags属性并清除已勾选的ToDo标签

代码修改方案

一、获取NoteTags的Id、Status、Type属性

原代码仅加载了段落的基础属性,需要补充加载noteTags集合及其子属性,修改逻辑如下:

  1. 调整paragraphs.load的入参,显式声明需要加载的noteTags属性
  2. 遍历段落时新增遍历noteTags集合,输出对应属性值

二、清除已勾选的ToDo标签

遍历所有NoteTag,筛选出类型为待办(ToDo)且状态为已完成(已勾选)的标签,调用remove方法移除,最后提交同步即可。

完整修改后代码

function getAndClearCompletedToDoTags() {
    OneNote.run(function (context) {
        var pageContents = context.application.getActivePage().contents;
        var pageContent = pageContents.getItemAt(0);
        var paragraphs = pageContent.outline.paragraphs;

        // 追加加载noteTags的相关属性
        paragraphs.load("id, type, richText, noteTags/id, noteTags/status, noteTags/type");
    
        return context.sync()
            .then(function () {
                $.each(paragraphs.items, function(index, paragraph) {
                    // 输出段落基础属性
                    console.log(
                        "Paragraph Id: " + paragraph.id +
                        "; Type: " + paragraph.type + 
                        "; Text: " + paragraph.richText.text);
                    
                    // 遍历当前段落的所有NoteTag
                    $.each(paragraph.noteTags.items, function(tagIdx, noteTag) {
                        // 输出NoteTag属性
                        console.log(
                            "  NoteTag Id: " + noteTag.id +
                            "; Status: " + noteTag.status + // 0=未完成/1=已完成/2=禁用
                            "; Type: " + noteTag.type // 枚举值对应不同标签类型,ToDo为0
                        );

                        // 筛选已勾选的ToDo标签并移除
                        if (noteTag.type === OneNote.NoteTagType.toDo && noteTag.status === OneNote.NoteTagStatus.completed) {
                            noteTag.remove();
                        }
                    })
                });
                // 提交标签移除的修改
                return context.sync();
            });
    })
    .catch(function(error) {
        onError(error);
    });   
}

补充说明

  • NoteTag的状态枚举:OneNote.NoteTagStatus.normal对应未勾选,OneNote.NoteTagStatus.completed对应已勾选
  • 若仅需修改勾选状态而非移除标签,可直接给noteTag.status赋值后同步即可,无需调用remove方法

内容的提问来源于stack exchange,提问作者mjRola

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.11 06:27:03