@@ -38,7 +38,7 @@ The following uses a single KV store as an example to describe the development p
2. Create a **KvManager** instance.
The sample code is as follows:
```
```js
letkvManager;
try{
constkvManagerConfig={
...
...
@@ -66,7 +66,7 @@ The following uses a single KV store as an example to describe the development p
2. Create a single KV store. You are advised to disable automatic synchronization (**autoSync:false**) and call **sync** if a synchronization is required.
The sample code is as follows:
```
```js
letkvStore;
try{
constoptions={
...
...
@@ -95,7 +95,7 @@ The following uses a single KV store as an example to describe the development p
4. Subscribe to changes in the distributed data.<br/>
The following is the sample code for subscribing to the data changes of a single KV store:
@@ -151,7 +151,7 @@ The following uses a single KV store as an example to describe the development p
Select the devices in the same network and the synchronization mode to synchronize data.
The following is the sample code for data synchronization in a single KV store. **deviceIds** can be obtained by deviceManager by calling **getTrustedDeviceListSync()**, and **1000** indicates that the maximum delay time is 1000 ms.
@@ -196,7 +196,7 @@ You can obtain the distributed table name for a remote device based on the local
The sample code is as follows:
```
```js
importdata_rdbfrom'@ohos.data.rdb'
constCREATE_TABLE_TEST="CREATE TABLE IF NOT EXISTS test ("+"id INTEGER PRIMARY KEY AUTOINCREMENT, "+"name TEXT NOT NULL, "+"age INTEGER, "+"salary REAL, "+"blobType BLOB)";
...
...
@@ -213,7 +213,7 @@ You can obtain the distributed table name for a remote device based on the local
@@ -176,7 +176,7 @@ Use the following APIs to delete a **Storage** instance or data file.
1. Import **@ohos.data.storage** and related modules to the development environment.
```
```js
import dataStorage from '@ohos.data.storage'
import featureAbility from '@ohos.ability.featureAbility' // Used to obtain the file storage path.
```
...
...
@@ -185,7 +185,7 @@ Use the following APIs to delete a **Storage** instance or data file.
Read the specified file and load its data to the **Storage** instance for data operations.
```
```js
var context = featureAbility.getContext()
var path = await context.getFilesDir()
let promise = dataStorage.getStorage(path + '/mystore')
...
...
@@ -196,7 +196,7 @@ Use the following APIs to delete a **Storage** instance or data file.
Use the **put\(\)** method of the **Storage** class to write data to the cached **Storage** instance.
```
```js
promise.then((storage) => {
let getPromise = storage.put('startup', 'auto') // Save data to the Storage instance.
getPromise.then(() => {
...
...
@@ -214,7 +214,7 @@ Use the following APIs to delete a **Storage** instance or data file.
Use the **get\(\)** method of the **Storage** class to read data.
```
```js
promise.then((storage) => {
let getPromise = storage.get('startup', 'default')
getPromise.then((value) => {
...
...
@@ -232,7 +232,7 @@ Use the following APIs to delete a **Storage** instance or data file.
Use the **flush** or **flushSync** method to flush data in the **Storage** instance to its file.
```
```js
storage.flush();
```
...
...
@@ -240,7 +240,7 @@ Use the following APIs to delete a **Storage** instance or data file.
Specify **StorageObserver** as the callback to subscribe to data changes for an application. When the value of the subscribed key is changed and the **flush\(\)** method is executed, **StorageObserver** will be invoked. Unregister the **StorageObserver** when it is no longer required.
```
```js
promise.then((storage) => {
var observer = function (key) {
console.info("The key of " + key + " changed.")
...
...
@@ -260,7 +260,7 @@ Use the following APIs to delete a **Storage** instance or data file.
Use the **deleteStorage** method to delete the **Storage** singleton of the specified file from the memory, and delete the specified file, its backup file, and damaged files. After the specified files are deleted, the application cannot use that instance to perform any data operation. Otherwise, data inconsistency will occur. The deleted data and files cannot be restored.
```
```js
let promise = dataStorage.deleteStorage(path + '/mystore')
@@ -105,7 +105,7 @@ You can implement page redirection through the [page router](../ui/ui-js-buildin
In the files of the first page, bind the **onclick** method to the button so that clicking the button redirects the user to the second page. This operation needs to be completed in both .js and .visual files.
- In the **index.js** file:
```
```js
importrouterfrom'@ohos.router';
exportdefault{
...
...
@@ -128,7 +128,7 @@ You can implement page redirection through the [page router](../ui/ui-js-buildin
constCREATE_TABLE_TEST="CREATE TABLE IF NOT EXISTS test ("+"id INTEGER PRIMARY KEY AUTOINCREMENT, "+"name TEXT NOT NULL, "+"age INTEGER, "+"salary REAL, "+"blobType BLOB)";