Blockly 已於 2025 年 11 月 10 日移交給 Raspberry Pi Foundation!請參閱網誌文章和常見問題。
Google uses AI technology to translate content into your preferred language. AI translations can contain errors.
儲存並載入
透過集合功能整理內容
你可以依據偏好儲存及分類內容。
序列化會儲存工作區的狀態,以便您進行載入
稍後返回工作區您會將所有必要資料轉換成
這種文字型格式
方便您儲存
建議您將工作區序列化為 JSON。
詳情請參閱序列化。
儲存
下列程式碼片段說明如何將工作區的狀態轉換為
用於儲存的 JSON:
// 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);
載入
下列程式碼片段說明如何將部分已儲存的狀態載入工作區:
// 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);
這樣就能建立所有已儲存的區塊、變數和
工作區
除非另有註明,否則本頁面中的內容是採用創用 CC 姓名標示 4.0 授權,程式碼範例則為阿帕契 2.0 授權。詳情請參閱《Google Developers 網站政策》。Java 是 Oracle 和/或其關聯企業的註冊商標。
上次更新時間:2025-07-25 (世界標準時間)。
[[["容易理解","easyToUnderstand","thumb-up"],["確實解決了我的問題","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["缺少我需要的資訊","missingTheInformationINeed","thumb-down"],["過於複雜/步驟過多","tooComplicatedTooManySteps","thumb-down"],["過時","outOfDate","thumb-down"],["翻譯問題","translationIssue","thumb-down"],["示例/程式碼問題","samplesCodeIssue","thumb-down"],["其他","otherDown","thumb-down"]],["上次更新時間:2025-07-25 (世界標準時間)。"],[],["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"]]