Blockly 于 2025 年 11 月 10 日移至 Raspberry Pi Foundation!请阅读博文和常见问题解答。
Google uses AI technology to translate content into your preferred language. AI translations can contain errors.
使用内置过程块
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
使用该插件
如需使用过程块,我们建议您使用
@blockly/block-shareable-procedures 插件。
如需了解插件块与内置块之间的区别,请参阅
概览。
安装
Yarn:
shell
yarn add @blockly/block-shareable-procedures
NPM:
shell
npm install @blockly/block-shareable-procedures
用法
import Blockly from 'blockly';
import {blocks, unregisterProcedureBlocks} '@blockly/block-shareable-procedures';
unregisterProcedureBlocks();
Blockly.common.defineBlocks(blocks);
这将定义与旧版内置过程块同名的过程块。因此,如果您加载使用旧过程块保存的 JSON 或 XML,它们将继续正常加载。
定义块(插件块或旧版内置块)后,您需要让用户可以使用这些块。这需要您使用类别样式的工具箱,因为过程类别是动态填充的,而弹出式工具箱不支持动态填充。
您可以按如下方式将动态类别添加到工具箱:
JSON
{
"kind": "categoryToolbox",
"contents": [
{
"kind": "category",
"name": "Functions",
"custom": "PROCEDURE"
}
]
};
XML
<xml id="toolbox" style="display: none">
<category name="Functions" custom="PROCEDURE">
</xml>
如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可获得了许可,并且代码示例已根据 Apache 2.0 许可获得了许可。有关详情,请参阅 Google 开发者网站政策。Java 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2026-05-13。
[[["易于理解","easyToUnderstand","thumb-up"],["解决了我的问题","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["没有我需要的信息","missingTheInformationINeed","thumb-down"],["太复杂/步骤太多","tooComplicatedTooManySteps","thumb-down"],["内容需要更新","outOfDate","thumb-down"],["翻译问题","translationIssue","thumb-down"],["示例/代码问题","samplesCodeIssue","thumb-down"],["其他","otherDown","thumb-down"]],["最后更新时间 (UTC):2026-05-13。"],[],["The `@blockly/block-shareable-procedures` plugin is recommended for using procedure blocks. Installation is done via Yarn or NPM. Usage involves importing `Blockly` and the plugin's `blocks`, then using the `unregisterProcedureBlocks()` and `Blockly.common.defineBlocks(blocks)` methods. This defines procedure blocks that maintain compatibility with legacy blocks. To make the blocks accessible, add a \"Functions\" category with the custom attribute \"PROCEDURE\" to your category-style toolbox, which is compatible with the dynamic procedure category.\n"]]