หากต้องการสร้างอินพุตที่กำหนดเอง คุณต้องคลาสย่อย Input
หรือหนึ่งในคลาสย่อย
class MyInput extends Blockly.inputs.Input {
// The constructor should always take in a name and a block to be compatible
// with JSON block definitions.
constructor(name, block) {
super(name, block);
// etc...
}
}
เลือกสร้างการเชื่อมต่อ
หากต้องการให้อินพุตมีการเชื่อมต่อ ก็ควรสร้างในเครื่องมือสร้างโดยเรียกใช้เมธอด makeConnection
constructor(name, block) {
super(name, block);
this.connection = this.makeConnection(ConnectionType.INPUT_VALUE);
}
ลงทะเบียนอินพุต
หากต้องการใช้อินพุตที่กำหนดเองในคำจำกัดความของบล็อก JSON คุณต้องลงทะเบียนและเชื่อมโยงกับสตริง
class MyInput extends Blockly.inputs.Input {}
Blockly.registry.register(Blockly.registry.Type.INPUT, 'my_input', MyInput);
ซึ่งต่างจากช่องที่กำหนดเอง