연구 설문조사: 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 MySubclassName(value);
}
필드 등록에 대한 자세한 내용은 JSON 및 등록을 참조하세요.
섹션을 참조하세요.
달리 명시되지 않는 한 이 페이지의 콘텐츠에는 Creative Commons Attribution 4.0 라이선스에 따라 라이선스가 부여되며, 코드 샘플에는 Apache 2.0 라이선스에 따라 라이선스가 부여됩니다. 자세한 내용은 Google Developers 사이트 정책을 참조하세요. 자바는 Oracle 및/또는 Oracle 계열사의 등록 상표입니다.
최종 업데이트: 2024-09-08(UTC)
[null,null,["최종 업데이트: 2024-09-08(UTC)"],[[["To extend an existing Blockly field, subclass a built-in field like `FieldTextInput` or `FieldColour` and modify its editor, on-block display, or displayed text."],["For custom fields with unique behaviors, subclass the base `Field` class instead of extending an existing field."],["Common field extensions involve customizing text input (`FieldTextInput`), numbers (`FieldNumber`), or dropdowns (`FieldDropdown`) to meet specific needs."],["When subclassing, ensure your constructor matches the super-constructor's signature and register the field with `Blockly.fieldRegistry.register`."],["Implement the `fromJson` method in your custom field class to enable compatibility with the Blockly JSON format for serialization and deserialization."]]],["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"]]