Labelfelder
Mit Sammlungen den Überblick behalten
Sie können Inhalte basierend auf Ihren Einstellungen speichern und kategorisieren.
In einem Labelfeld wird ein String als value
und ein String als text
gespeichert. value
und text
eines Labelfelds sind immer identisch.
Labelfeld

Labelfeld für minimierten Block

Erstellung
JSON
{
"type": "example_label",
"message0": "a label %1 and another label",
"args0": [
{
"type": "input_dummy"
}
]
}
Der Text zwischen den Interpolationsargumenten wird zu Labelstrings.
Alternativ können Labels explizit interpoliert werden, entweder als Objekt oder als Text. Dies wird in der Regel nicht empfohlen, da es die Übersetzung erschwert.
{
"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');
}
};
Die Funktion appendField akzeptiert sowohl FieldLabel
-Objekte als auch Strings, um Labels zu erstellen.
Das Labelfeld kann einen optionalen Wert und einen optionalen CSS-Klassenstring enthalten.
Beide sind standardmäßig auf einen leeren String eingestellt.
Serialisierung
Labelfelder können nicht serialisiert werden.
Wenn Sie möchten, dass Ihr Label serialisiert wird, weil es programmatisch geändert wird, sehen Sie sich das Feld Serialisierbares Label an.
Validatoren
Labelfelder unterstützen keine Validierungsregeln, da sie nicht bearbeitbar sind.
Sofern nicht anders angegeben, sind die Inhalte dieser Seite unter der Creative Commons Attribution 4.0 License und Codebeispiele unter der Apache 2.0 License lizenziert. Weitere Informationen finden Sie in den Websiterichtlinien von Google Developers. Java ist eine eingetragene Marke von Oracle und/oder seinen Partnern.
Zuletzt aktualisiert: 2025-07-25 (UTC).
[null,null,["Zuletzt aktualisiert: 2025-07-25 (UTC)."],[[["\u003cp\u003eA label field displays text on a block and stores the same string as both its \u003ccode\u003evalue\u003c/code\u003e and \u003ccode\u003etext\u003c/code\u003e.\u003c/p\u003e\n"],["\u003cp\u003eLabel fields can be created using JSON by specifying message strings or by explicitly interpolating labels, though the latter is discouraged for translation reasons.\u003c/p\u003e\n"],["\u003cp\u003eIn JavaScript, label fields are created using \u003ccode\u003eBlockly.FieldLabel\u003c/code\u003e and appended to block inputs using \u003ccode\u003eappendField\u003c/code\u003e.\u003c/p\u003e\n"],["\u003cp\u003eWhile not serializable by default, a separate "Serializable Label" field exists for cases requiring programmatic changes and serialization.\u003c/p\u003e\n"],["\u003cp\u003eLabel fields do not support validators due to their non-editable nature.\u003c/p\u003e\n"]]],[],null,["# Label fields\n\nA label field stores a string as its `value` and a string as its `text`. The\n`value` and `text` of a label field are always the same.\n\n#### Label field\n\n#### Label field on collapsed block\n\nCreation\n--------\n\n### JSON\n\n {\n \"type\": \"example_label\",\n \"message0\": \"a label %1 and another label\",\n \"args0\": [\n {\n \"type\": \"input_dummy\"\n }\n ]\n }\n\nAny message text between interpolation arguments becomes label strings.\nAlternatively, labels may be interpolated explicitly, either as an object or\nas text. This is generally discouraged as it makes translation more\ndifficult. \n\n {\n \"type\": \"example_label\",\n \"message0\": \"%1 %2 %3\",\n \"args0\": [\n {\n \"type\": \"field_label\",\n \"text\": \"a label\"\n },\n {\n \"type\": \"input_dummy\"\n },\n \"and another label\"\n ]\n }\n\n### JavaScript\n\n Blockly.Blocks['example_label'] = {\n init: function() {\n this.appendDummyInput()\n .appendField(new Blockly.FieldLabel('a label'));\n this.appendDummyInput()\n .appendField('and another label');\n }\n };\n\nThe [appendField](/blockly/reference/js/Blockly.Input#appendField)\nfunction accepts both `FieldLabel` objects and, more commonly, strings to create\nlabels.\n\nThe label field takes in an optional value, and an optional css class string.\nBoth default to an empty string.\n\nSerialization\n-------------\n\nLabel fields are not serializable.\n\nIf you would like your label to be serialized, because it is being changed\nprogrammatically, see the [Serializable Label](/blockly/guides/create-custom-blocks/fields/built-in-fields/label-serializable)\nfield.\n\nValidators\n----------\n\nLabel fields do not support validators, because they are not editable."]]