Bản khảo sát nghiên cứu: Cho chúng tôi biết trải nghiệm của bạn khi sử dụng Blockly
Bắt đầu khảo sát
chặn > CodeGenerator > blockToCode
Phương thức CodeGenerator.blockToCode()
Tạo mã cho khối được chỉ định (và các khối đính kèm). Bạn phải khởi tạo trình tạo trước khi gọi hàm này.
Chữ ký:
blockToCode(block: Block | null, opt_thisOnly?: boolean): string | [string, number];
Tham số
Thông số |
Loại |
Mô tả |
chặn |
Chặn | rỗng |
Khối để tạo mã. |
opt_thisOnly |
boolean |
(Không bắt buộc) True để chỉ tạo mã cho câu lệnh này. |
Trường hợp trả lại hàng:
chuỗi | [chuỗi, số]
Đối với khối câu lệnh, mã được tạo. Đối với khối giá trị, một mảng chứa mã được tạo và giá trị thứ tự của toán tử. Trả về '' nếu khối là rỗng.
Trừ phi có lưu ý khác, nội dung của trang này được cấp phép theo Giấy phép ghi nhận tác giả 4.0 của Creative Commons và các mẫu mã lập trình được cấp phép theo Giấy phép Apache 2.0. Để biết thông tin chi tiết, vui lòng tham khảo Chính sách trang web của Google Developers. Java là nhãn hiệu đã đăng ký của Oracle và/hoặc các đơn vị liên kết với Oracle.
Cập nhật lần gần đây nhất: 2024-08-21 UTC.
[null,null,["Cập nhật lần gần đây nhất: 2024-08-21 UTC."],[[["The `blockToCode` method generates code for a specified Blockly block and any attached blocks."],["It requires the code generator to be initialized before use and accepts the block and an optional flag to generate code for only the given block."],["The method returns the generated code as a string for statement blocks or an array containing the code and an operator precedence for value blocks, returning an empty string if the input block is null."]]],["The `blockToCode` method generates code for a specified block and its attachments. It requires prior initialization of the code generator. It accepts a block and an optional boolean `opt_thisOnly` to limit code generation to only the provided block. The method returns either a string representing the generated code for statement blocks or an array containing code and operator order for value blocks. If the provided block is null it will return an empty string.\n"]]