연구 설문조사: Blockly 사용 경험을 알려주세요
설문조사 시작
기존 필드 확장
컬렉션을 사용해 정리하기
내 환경설정을 기준으로 콘텐츠를 저장하고 분류하세요.
기존 필드를 확장하려면 기본 제공 필드 (예:
FieldTextInput
, FieldColour
)을 사용하여 필요에 맞게 일부를 수정할 수 있습니다.
다음은 수정할 수 있는 필드의 일부입니다.
광고주의
커스텀 필드
기본 제공 필드에서 동작이 필요하지 않은 경우 Field
의 서브클래스를 생성해야 합니다.
일반적인 확장 프로그램
대부분의 맞춤 필드는 다음 세 가지 유형 중 하나를 확장합니다.
- 텍스트 입력: 사용자가 입력란에 입력하도록 하려면
FieldTextInput
입니다.
- 숫자: 숫자를 저장하려면
FieldNumber
를 확장해야 합니다.
- 드롭다운: 드롭다운을 만들고 싶지만 다른 모델을 저장하고자 하는 경우
기본 문자열 또는 이미지 모델보다 더 효율적이면
FieldDropdown
를 확장해야 합니다.
- 주의:
FieldDropdown
를 확장하기 전에 드롭다운 필드의
맞춤설정 옵션으로는 요구사항을 충족할 수 없습니다.
경우에 따라 다른 필드 유형을 확장할 수 있습니다. 대상
예시 FieldLabelSerializable
는 FieldLabel
를 확장합니다.
서브클래스화
import * as Blockly from 'blockly';
export class MyCustomTextField extends Blockly.FieldTextInput {
constructor(value, validator, config) {
super(value, validator, config);
}
}
필드의 서브클래스에 대한 생성자는 다음 필드의 생성자와 매우 유사합니다.
커스텀 필드를 사용합니다. 하위 생성자의 서명은
일반적으로 상위 생성자의 서명과 일치합니다.
JSON 및 등록
또한 필드를 한 번 등록해야 합니다.
Blockly.fieldRegistry.register('my_custom_text_field', MyCustomTextField);
그리고 다음과 함께 작동하도록 클래스에서 fromJson
의 구현을 제공합니다.
JSON 형식
static fromJson(options) {
const value = Blockly.utils.parsing.replaceMessageReferences(options.value);
return new MyCustomTextField(value);
}
필드 등록에 대한 자세한 내용은 JSON 및 등록을 참조하세요.
섹션을 참조하세요.
달리 명시되지 않는 한 이 페이지의 콘텐츠에는 Creative Commons Attribution 4.0 라이선스에 따라 라이선스가 부여되며, 코드 샘플에는 Apache 2.0 라이선스에 따라 라이선스가 부여됩니다. 자세한 내용은 Google Developers 사이트 정책을 참조하세요. 자바는 Oracle 및/또는 Oracle 계열사의 등록 상표입니다.
최종 업데이트: 2025-08-20(UTC)
[null,null,["최종 업데이트: 2025-08-20(UTC)"],[[["\u003cp\u003eTo extend an existing Blockly field, subclass a built-in field like \u003ccode\u003eFieldTextInput\u003c/code\u003e or \u003ccode\u003eFieldColour\u003c/code\u003e and modify its editor, on-block display, or displayed text.\u003c/p\u003e\n"],["\u003cp\u003eFor custom fields with unique behaviors, subclass the base \u003ccode\u003eField\u003c/code\u003e class instead of extending an existing field.\u003c/p\u003e\n"],["\u003cp\u003eCommon field extensions involve customizing text input (\u003ccode\u003eFieldTextInput\u003c/code\u003e), numbers (\u003ccode\u003eFieldNumber\u003c/code\u003e), or dropdowns (\u003ccode\u003eFieldDropdown\u003c/code\u003e) to meet specific needs.\u003c/p\u003e\n"],["\u003cp\u003eWhen subclassing, ensure your constructor matches the super-constructor's signature and register the field with \u003ccode\u003eBlockly.fieldRegistry.register\u003c/code\u003e.\u003c/p\u003e\n"],["\u003cp\u003eImplement the \u003ccode\u003efromJson\u003c/code\u003e method in your custom field class to enable compatibility with the Blockly JSON format for serialization and deserialization.\u003c/p\u003e\n"]]],["To extend an existing field, subclass a built-in field like `FieldTextInput` or `FieldColour`, modifying its editor, on-block display, or text. For unique fields, subclass `Field`. Common extensions include `FieldTextInput`, `FieldNumber`, and `FieldDropdown`. Subclass constructors should mirror the super-constructor's signature. Register the field using `Blockly.fieldRegistry.register()` and implement `fromJson` for JSON compatibility. Extending different fields such as `FieldLabelSerializable` is also possible.\n"],null,["# Extend an existing field\n\nIn order to extend an existing field you must subclass a built in field (e.g\n`FieldTextInput`, `FieldColour`) and then modify part of it to fit your needs.\nSome parts of a field you can modify are:\n\n- Its [editor](/blockly/guides/create-custom-blocks/fields/anatomy-of-a-field#editor_display).\n- Its [on-block display](/blockly/guides/create-custom-blocks/fields/anatomy-of-a-field#on-block_display).\n- The [text](/blockly/guides/create-custom-blocks/fields/anatomy-of-a-field#text) it displays.\n\nIf you want to [create a\ncustom field](/blockly/guides/create-custom-blocks/fields/customizing-fields/creating)\nthat does not need behaviour from any built-in field you should subclass `Field`.\n\nCommon extensions\n-----------------\n\nMost custom fields extend one of these three types:\n\n- [Text Input](/blockly/guides/create-custom-blocks/fields/built-in-fields/text-input): If you want your users to type into your field, you should extend `FieldTextInput`.\n- [Number](/blockly/guides/create-custom-blocks/fields/built-in-fields/number): If you want to store a number, you should extend `FieldNumber`.\n- [Dropdown](/blockly/guides/create-custom-blocks/fields/built-in-fields/dropdown): If you want to create a dropdown, but you want it to store a different model than the default string or image model, you should extend `FieldDropdown`.\n - Caution: Before extending `FieldDropdown`, check that the dropdown field's [customization options](/blockly/guides/create-custom-blocks/fields/built-in-fields/dropdown#customization) cannot fulfill your needs.\n\nUnder certain circumstances you may wish to extend a different field type. For\nexample `FieldLabelSerializable` extends `FieldLabel`.\n\nSubclassing\n-----------\n\n import * as Blockly from 'blockly';\n\n export class MyCustomTextField extends Blockly.FieldTextInput {\n\n constructor(value, validator, config) {\n super(value, validator, config);\n }\n }\n\nThe constructor for a field's subclass looks very similar to the [constructor for\na custom field](/blockly/guides/create-custom-blocks/fields/customizing-fields/creating#implementing_a_constructor). The signature of the sub-constructor should\ngenerally match the signature of the super-constructor.\n\nJSON and registration\n---------------------\n\nYou should also register the field once: \n\n Blockly.fieldRegistry.register('my_custom_text_field', MyCustomTextField);\n\nand provide an implementation of `fromJson` in the class so that it works with\nthe JSON format: \n\n static fromJson(options) {\n const value = Blockly.utils.parsing.replaceMessageReferences(options.value);\n return new MyCustomTextField(value);\n }\n\nFor more information about registering a field see the [JSON and registration](/blockly/guides/create-custom-blocks/fields/customizing-fields/creating#json_and_registration)\nsection in Creating a Custom Field."]]