标签字段

标签字段会将字符串存储为 value,并将字符串存储为 text。标签字段的 valuetext 始终相同。

标签字段

包含两行的代码块。第一个标签为“a label”,第二个标签为“and another label”。

收起的版块上的标签字段

收起后的同一代码块。它只有一行,标签为“a label and another label”,右边缘锯齿状,表示其处于收起状态。

创建

JSON

{
  "type": "example_label",
  "message0": "a label %1 and another label",
  "args0": [
    {
      "type": "input_dummy"
    }
  ]
}

插值参数之间的任何消息文本都会变为标签字符串。或者,您也可以明确插入标签,以对象或文本的形式插入。通常不建议这样做,因为这会增加翻译难度。

{
  "type": "example_label",
  "message0": "%1 %2 %3",
  "args0": [
    {
      "type": "field_label",
      "text": "a label"
    },
    {
      "type": "input_dummy"
    },
    "and another label"
  ]
}

JavaScript

Blockly.Blocks['example_label'] = {
  init: function() {
    this.appendDummyInput()
        .appendField(new Blockly.FieldLabel('a label'));
    this.appendDummyInput()
        .appendField('and another label');
  }
};

appendField 函数接受 FieldLabel 对象,也接受字符串(更常见)来创建标签。

label 字段接受一个可选值和一个可选的 CSS 类字符串。两者均默认为空字符串。

序列化

标签字段不可序列化。

如果您希望标签进行序列化(因为它会通过编程方式进行更改),请参阅可序列化标签字段。

验证器

标签字段不支持验证器,因为它们不可修改。