แบบสำรวจการวิจัย: บอกให้เราทราบเกี่ยวกับประสบการณ์การใช้งาน Blockly
เริ่มแบบสำรวจ
ใบแจ้งยอดประจำเดือน
บล็อกคำสั่งเป็นบล็อกที่ไม่มีการเชื่อมต่อเอาต์พุต การดำเนินการเหล่านี้
ในภาษาที่ใช้ข้อความ
บล็อกคำสั่งเปลี่ยนเป็นโค้ดได้เช่นเดียวกับบล็อกอื่นๆ ใน Blockly
โดยการกำหนดโปรแกรมสร้างโค้ดบล็อก
import {javascriptGenerator} from 'blockly/javascript';
javascriptGenerator.forBlock['custom_block'] = function(block, generator) {
// Collect argument strings.
const fieldValue = block.getFieldValue('MY_FIELD');
const innerCode = generator.statementToCode(block, 'MY_STATEMENT_INPUT');
// Return code.
return 'my code string';
}
รวบรวมสตริงอาร์กิวเมนต์
เครื่องมือสร้างบล็อกโค้ดทั้งหมดต้องใช้
รวบรวมค่าของช่องและรวบรวมโค้ดของ
บล็อกภายใน
// Collect field values.
const fieldValue = block.getFieldValue('MY_FIELD');
// Collect inner block code strings.
const innerCode = generator.statementToCode(block, 'MY_STATEMENT_INPUT');
หากคุณอ้างอิงโค้ดของบล็อกภายในหลายครั้ง คุณควรเพิ่ม
การแคชอาร์กิวเมนต์ลงในบล็อกของคุณ
แสดงผลค่า
ประเภทการแสดงผลของโปรแกรมสร้างโค้ดบล็อกคำสั่งคือสตริงโค้ด
return 'my code string';
เนื้อหาของหน้าเว็บนี้ได้รับอนุญาตภายใต้ใบอนุญาตที่ต้องระบุที่มาของครีเอทีฟคอมมอนส์ 4.0 และตัวอย่างโค้ดได้รับอนุญาตภายใต้ใบอนุญาต Apache 2.0 เว้นแต่จะระบุไว้เป็นอย่างอื่น โปรดดูรายละเอียดที่นโยบายเว็บไซต์ Google Developers Java เป็นเครื่องหมายการค้าจดทะเบียนของ Oracle และ/หรือบริษัทในเครือ
อัปเดตล่าสุด 2024-10-15 UTC
[null,null,["อัปเดตล่าสุด 2024-10-15 UTC"],[[["Statement blocks in Blockly, similar to statements in text-based languages, lack output connections and function by defining a block-code generator to convert them into code strings."],["Generating code for statement blocks involves collecting values from fields and inner blocks using dedicated functions within the block-code generator."],["Block-code generators for statement blocks return code strings, representing the translated code for the block, and optionally incorporate argument caching for optimized code generation."]]],["Statement blocks, which lack output connections, are converted to code strings using block-code generators. This process involves collecting values from fields and code from inner blocks. The `getFieldValue` method retrieves field values, while `statementToCode` gathers inner block code. If inner block code is used multiple times, argument caching is recommended. Ultimately, a statement block-code generator returns a string representing the generated code.\n"]]