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

收起块中的标签字段

创建
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 对象和(更常见的是)字符串来创建标签。
标签字段接受一个可选值和一个可选的 CSS 类字符串。 两者均默认为空字符串。
序列化
标签字段不可序列化。
如果您希望序列化标签(因为标签是通过程序化方式更改的),请参阅 Serializable Label 字段。
验证器
标签字段不支持验证器,因为它们不可修改。
