标签字段将字符串存储为其 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
对象,更常见的是字符串来创建标签。
label 字段包含一个可选值和一个可选的 css 类字符串。 两者均默认为空字符串。
序列化
标签字段不可序列化。
如果您希望对标签进行序列化,因为该标签是以编程方式进行更改的,请参阅可序列化标签字段。
验证器
标签字段不支持验证器,因为它们无法修改。