研究调查问卷:请告诉我们您使用 Blockly 的体验
开始调查问卷
可序列化标签字段
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
可序列化标签的运作方式与普通标签完全相同,只不过它们还会序列化为 XML。只有在以编程方式修改标签内容并希望将其序列化为 XML 时,才应使用这些方法。
可序列化标签字段

收起的代码块上的可序列化标签字段

创建
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");
}
};
可序列化的标签字段接受一个可选值和一个可选的 CSS 类字符串。两者均默认为空字符串。
序列化
JSON
可序列化的标签字段的 JSON 如下所示:
{
"fields": {
"FIELDNAME": text
}
}
其中 FIELDNAME
是引用可序列化标签字段的字符串,值是应用于该字段的值。该值遵循与构造函数值相同的规则。
XML
可序列化的标签字段的 XML 如下所示:
<field name="FIELDNAME">text</field>
field
节点的 name
属性包含一个引用可序列化标签字段的字符串,并且节点的内部文本是应用于该字段的值。
验证器
可序列化标签字段不支持验证器,因为用户无法对其进行修改。
如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可获得了许可,并且代码示例已根据 Apache 2.0 许可获得了许可。有关详情,请参阅 Google 开发者网站政策。Java 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-06-17。
[[["易于理解","easyToUnderstand","thumb-up"],["解决了我的问题","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["没有我需要的信息","missingTheInformationINeed","thumb-down"],["太复杂/步骤太多","tooComplicatedTooManySteps","thumb-down"],["内容需要更新","outOfDate","thumb-down"],["翻译问题","translationIssue","thumb-down"],["示例/代码问题","samplesCodeIssue","thumb-down"],["其他","otherDown","thumb-down"]],["最后更新时间 (UTC):2025-06-17。"],[[["Serializable labels function identically to regular labels but with the added capability of serializing to XML for programmatic content editing."],["These labels are defined using JSON or JavaScript, specifying their type, message, arguments, and field name."],["Serialization of serializable labels is achieved through JSON or XML, representing the field name and its corresponding text value."],["Unlike regular labels, serializable labels lack validator support due to their non-editable nature."]]],[]]