工具箱

工具箱包含用于编程的块。这些块可以拖动到工作区中。

如需详细了解工具箱的外观,请参阅可视化术语表

基本定义

工具箱定义指定了包含在工具箱中的块以及按什么顺序添加。工具箱的大部分外观和样式都是通过其他方式指定的。

我们建议您使用 JSON 定义工具箱。

以下代码段定义了包含两个代码块的浮出工具箱:

const toolbox = {
  // There are two kinds of toolboxes. The simpler one is a flyout toolbox.
  kind: 'flyoutToolbox',
  // The contents is the blocks and other items that exist in your toolbox.
  contents: [
    {
      kind: 'block',
      type: 'controls_if'
    },
    {
      kind: 'block',
      type: 'controls_whileUntil'
    }
    // You can add more blocks to this array.
  ]
};

// The toolbox gets passed to the configuration struct during injection.
const workspace = Blockly.inject('blocklyDiv', {toolbox: toolbox});

如需详细了解如何定义和配置工具箱,请参阅工具箱概览

如需详细了解注入,请参阅创建工作区