Survei Riset: Ceritakan pengalaman Anda dengan Blockly
Mulai survei
Serialisasi
Serialisasi menyimpan status ruang kerja Anda agar dapat dimuat
kembali ke ruang kerja nanti. Anda mengonversi semua data yang
perlu Anda simpan ke dalam
format berbasis teks untuk
penyimpanan yang mudah.
Sebaiknya serialisasi ruang kerja Anda ke JSON.
Untuk mengetahui informasi selengkapnya, lihat Serialisasi.
Simpan
Cuplikan kode berikut menunjukkan cara mengonversi status ruang kerja Anda menjadi
JSON untuk menyimpan:
// 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);
Muat
Cuplikan kode berikut menunjukkan cara memuat beberapa status tersimpan ke ruang kerja:
// 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);
Ini akan membuat semua blok, variabel, dan elemen lain yang Anda simpan di
Workspace.
Kecuali dinyatakan lain, konten di halaman ini dilisensikan berdasarkan Lisensi Creative Commons Attribution 4.0, sedangkan contoh kode dilisensikan berdasarkan Lisensi Apache 2.0. Untuk mengetahui informasi selengkapnya, lihat Kebijakan Situs Google Developers. Java adalah merek dagang terdaftar dari Oracle dan/atau afiliasinya.
Terakhir diperbarui pada 2024-11-04 UTC.
[null,null,["Terakhir diperbarui pada 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"]]