保存并加载
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
序列化会保存工作区的状态,以便进行加载
返回工作区。您需要将需要保存的所有数据
一种方便存储的文本格式
我们建议您将工作区序列化为 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);
这样系统就会创建所有已保存的块、变量和
工作区。
如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可获得了许可,并且代码示例已根据 Apache 2.0 许可获得了许可。有关详情,请参阅 Google 开发者网站政策。Java 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-07-25。
[null,null,["最后更新时间 (UTC):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"],null,[]]