我们可以禁用上下文功能区中的菜单项吗?

问题描述 投票:0回答:1

在我的项目中,我使用 Office.riboon 方法动态生成功能区。但是,问题是我无法禁用菜单项,只能启用和禁用控件。

那么,有什么方法可以使用 Office 功能区 API 启用或禁用菜单项吗?

用于动态生成上下文功能区的 Ribbon API

javascript excel office-js
1个回答
0
投票

是的。动态功能区架构为菜单项提供了“启用”属性:以下是相关摘录。请注意,menuItemElement 继承了 actionableElement 的属性。

"actionableElement": {
        "$comment": "An abstract type represents controls which can trigger an action.",
        "allOf": [
            {
                "$ref": "#/definitions/buttonLikeElement"
            },
            {
                "properties": {
                    "enabled": {
                        "title": "Title",
                        "description": "Specifies whether the control is enabled when the ribbon is generated.",
                        "type": "boolean",
                        "default": true
                    },
                    "actionId": {
                        "title": "Action ID",
                        "description": "The action to perform.",
                        "type": "string"
                    }
                },
                "required": [
                    "actionId"
                ]
            }
        ],
        "additionalProperties": false
    },
...
 "menuItemElement": {
        "title": "Menu Item Element",
        "description": "A menu item element in a menu.",
        "allOf": [
            {
                "$ref": "#/definitions/actionableElement"
            },
            {
                "properties": {
                    "type": {
                        "title": "Type",
                        "description": "Type of the element.",
                        "const": "MenuItem"
                    }
                },
                "required": [
                    "type"
                ]
            }
        ],
        "additionalProperties": false
    },

整个架构位于:dynamic-ribbon-schema

您可以使用 Office.ribbon.requestUpdate() 方法设置“enabled”属性。示例位于:启用和禁用加载项命令

© www.soinside.com 2019 - 2024. All rights reserved.