Campos de rótulos serializáveis
Mantenha tudo organizado com as coleções
Salve e categorize o conteúdo com base nas suas preferências.
Os rótulos serializáveis funcionam exatamente como os rótulos normais,
exceto por serem serializados em XML. Elas só devem ser usadas se você estiver editando
o conteúdo de um rótulo de forma programática e quiser serializar para XML.
Campo de rótulo serializável

Campo de marcador serializável em um bloco fechado

Criação
JSON
{
"type": "example_serializable_label",
"message0": "%1",
"args0": [
{
"type": "field_label_serializable",
"name": "FIELDNAME",
"text": "a serializable label"
}
]
}
JavaScript
Blockly.Blocks['example_serializable_label'] = {
init: function() {
this.appendDummyInput()
.appendField(new Blockly.FieldLabelSerializable("a serializable label"), "FIELDNAME");
}
};
O campo de rótulo serializável recebe um valor opcional e uma string de classe
CSS opcional. O padrão é uma string vazia.
Serialização
JSON
O JSON de um campo de rótulo serializável é parecido com este:
{
"fields": {
"FIELDNAME": text
}
}
Em que FIELDNAME
é uma string que faz referência a um campo de rótulo serializável e
o valor é o valor a ser aplicado ao campo. O valor
segue as mesmas regras do valor do construtor.
XML
O XML de um campo de rótulo serializável tem esta aparência:
<field name="FIELDNAME">text</field>
O atributo name
do nó field
contém uma string que faz referência a um campo de rótulo
serializável, e o texto interno do nó é o valor a ser aplicado ao campo.
Validadores
Os campos de rótulo serializáveis não oferecem suporte a validadores porque não podem ser
editados por um usuário.
Exceto em caso de indicação contrária, o conteúdo desta página é licenciado de acordo com a Licença de atribuição 4.0 do Creative Commons, e as amostras de código são licenciadas de acordo com a Licença Apache 2.0. Para mais detalhes, consulte as políticas do site do Google Developers. Java é uma marca registrada da Oracle e/ou afiliadas.
Última atualização 2025-07-26 UTC.
[null,null,["Última atualização 2025-07-26 UTC."],[[["\u003cp\u003eSerializable labels function identically to regular labels but with the added capability of serializing to XML for programmatic content editing.\u003c/p\u003e\n"],["\u003cp\u003eThese labels are defined using JSON or JavaScript, specifying their type, message, arguments, and field name.\u003c/p\u003e\n"],["\u003cp\u003eSerialization of serializable labels is achieved through JSON or XML, representing the field name and its corresponding text value.\u003c/p\u003e\n"],["\u003cp\u003eUnlike regular labels, serializable labels lack validator support due to their non-editable nature.\u003c/p\u003e\n"]]],[],null,["# Serializable label fields\n\nSerializable labels work exactly the same as [normal labels](/blockly/guides/create-custom-blocks/fields/built-in-fields/label)\nexcept they also serialize to XML. They should only be used if you are editing\nthe content of a label programmatically, and wish it to serialize to XML.\n\n#### Serializable label field\n\n#### Serializable label field on a collapsed block\n\nCreation\n--------\n\n### JSON\n\n {\n \"type\": \"example_serializable_label\",\n \"message0\": \"%1\",\n \"args0\": [\n {\n \"type\": \"field_label_serializable\",\n \"name\": \"FIELDNAME\",\n \"text\": \"a serializable label\"\n }\n ]\n }\n\n### JavaScript\n\n Blockly.Blocks['example_serializable_label'] = {\n init: function() {\n this.appendDummyInput()\n .appendField(new Blockly.FieldLabelSerializable(\"a serializable label\"), \"FIELDNAME\");\n }\n };\n\nThe serializable label field takes in an optional value, and an optional css\nclass string. Both default to an empty string.\n\nSerialization\n-------------\n\n### JSON\n\nThe JSON for a serializable label field looks like so: \n\n {\n \"fields\": {\n \"FIELDNAME\": text\n }\n }\n\nWhere `FIELDNAME` is a string referencing a serializable label field, and\nthe value is the value to apply to the field. The value\nfollows the same rules as the constructor value.\n\n### XML\n\nThe XML for a serializable label field looks like so: \n\n \u003cfield name=\"FIELDNAME\"\u003etext\u003c/field\u003e\n\nThe `field` node's `name` attribute contains a string referencing a serializable\nlabel field, and the node's inner text is the value to apply to the field.\n\nValidators\n----------\n\nSerializable label fields do not support validators, because they are not\neditable by a user."]]