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
Chuyển đổi tuần tự
Quá trình chuyển đổi tuần tự là lưu trạng thái của không gian làm việc để có thể tải lại trạng thái đó vào không gian làm việc sau này. Bạn chuyển đổi tất cả dữ liệu cần lưu thành
một định dạng dựa trên văn bản để dễ dàng lưu trữ.
Bạn nên chuyển đổi tuần tự không gian làm việc của mình sang JSON.
Để biết thêm thông tin, hãy xem phần Chuyển đổi tuần tự.
Lưu
Đoạn mã sau đây cho biết cách chuyển đổi trạng thái của không gian làm việc thành JSON để lưu:
// Serialize the state.
const state = Blockly.serialization.workspaces.save(myWorkspace);
// Then you save the state, e.g. to local storage.
localStorage.setItem('workspace-state', state);
Tải
Đoạn mã sau đây cho biết cách tải một số trạng thái đã lưu vào không gian làm việc:
// Get your saved state from somewhere, e.g. local storage.
const state = localStorage.getItem('workspace-state');
// Deserialize the state.
Blockly.serialization.workspaces.load(state, myWorkspace);
Thao tác này sẽ tạo tất cả các khối, biến và thành phần khác đã lưu trong
Workspace.
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-11-04 UTC.
[null,null,["Cập nhật lần gần đây nhất: 2024-11-04 UTC."],[[["Serialization allows you to save the current state of your Blockly workspace (blocks, variables, etc.) into a text-based format, typically JSON, for later retrieval."],["You can save the serialized workspace data to a storage location like local storage and then load it back into a workspace to restore its previous state."],["Blockly provides APIs (`Blockly.serialization.workspaces.save` and `Blockly.serialization.workspaces.load`) for easily serializing and deserializing workspace states."]]],["Serialization saves workspace states for later loading by converting data into a text-based format, preferably JSON. To save, use `Blockly.serialization.workspaces.save(myWorkspace)` to get the state, then store it (e.g., in local storage). To load, retrieve the saved state and use `Blockly.serialization.workspaces.load(state, myWorkspace)` to recreate blocks, variables, and other elements in the workspace.\n"]]