Mevcut bir alanı genişletme
Koleksiyonlar ile düzeninizi koruyun
İçeriği tercihlerinize göre kaydedin ve kategorilere ayırın.
Mevcut bir alanı genişletmek için yerleşik bir alanın alt sınıfına girmeniz gerekir (ör.
FieldTextInput
, FieldColour
) sonra da dosyanın bir kısmını ihtiyaçlarınıza göre değiştirebilirsiniz.
Bir alanın değiştirebileceğiniz bazı bölümleri şunlardır:
Yeni bir web sitesi oluşturmak
özel alan
yerleşik bir alandan davranış gerektirmeyen Field
alt sınıfını kullanmanız gerekir.
Sık kullanılan uzantılar
Çoğu özel alan, aşağıdaki üç türden birine genişler:
- Metin Girişi: Kullanıcılarınızın alanınıza yazmasını istiyorsanız
FieldTextInput
.
- Numara: Bir numarayı saklamak istiyorsanız
FieldNumber
değerini uzatmanız gerekir.
- Açılır liste: Açılır liste oluşturmak, ancak farklı bir model depolamasını istiyorsanız
varsayılan dize veya resim modelinden daha fazlaysa
FieldDropdown
öğesini genişletmeniz gerekir.
- Dikkat:
FieldDropdown
öğesini genişletmeden önce açılır menü alanının
özelleştirme seçenekleri ihtiyaçlarınızı karşılayamaz.
Belirli koşullar altında farklı bir alan türünü genişletmek isteyebilirsiniz. Örneğin,
örnek FieldLabelSerializable
, FieldLabel
öğesini genişletir.
Alt Sınıflandırma
import * as Blockly from 'blockly';
export class MyCustomTextField extends Blockly.FieldTextInput {
constructor(value, validator, config) {
super(value, validator, config);
}
}
Bir alanın alt sınıfının oluşturucusu,
kullanabilirsiniz. Alt oluşturucunun imzası
süper oluşturucunun imzasıyla eşleşir.
JSON ve kayıt
Alanı bir kez kaydetmeniz de gerekir:
Blockly.fieldRegistry.register('my_custom_text_field', MyCustomTextField);
vefromJson
JSON biçimi:
static fromJson(options) {
const value = Blockly.utils.parsing.replaceMessageReferences(options.value);
return new MyCustomTextField(value);
}
Alan kaydetme hakkında daha fazla bilgi için JSON ve kayıt sayfasına bakın.
bölümünü inceleyin.
Aksi belirtilmediği sürece bu sayfanın içeriği Creative Commons Atıf 4.0 Lisansı altında ve kod örnekleri Apache 2.0 Lisansı altında lisanslanmıştır. Ayrıntılı bilgi için Google Developers Site Politikaları'na göz atın. Java, Oracle ve/veya satış ortaklarının tescilli ticari markasıdır.
Son güncelleme tarihi: 2025-08-20 UTC.
[null,null,["Son güncelleme tarihi: 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."]]