未验证 提交 8a3728ab 编写于 作者: O openharmony_ci 提交者: Gitee

!9982 【翻译完成】#I5OTIF

Merge pull request !9982 from Annie_wang/PR8877A
......@@ -90,9 +90,9 @@ Use the following APIs to delete a **Storage** instance or data file.
context.getFilesDir().then((filePath) => {
path = filePath;
console.info("======================>getFilesDirPromsie====================>");
let promise = dataStorage.getStorage(path + '/mystore');
});
let promise = dataStorage.getStorage(path + '/mystore');
```
......@@ -118,18 +118,19 @@ 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) => {
console.info("The value of startup is " + value);
}).catch((err) => {
console.info("Failed to get the value of startup with err: " + err);
})
}).catch((err) => {
console.info("Failed to get the storage.");
})
```
```js
promise.then((storage) => {
let getPromise = storage.get('startup', 'default')
getPromise.then((value) => {
console.info("The value of startup is " + value);
}).catch((err) => {
console.info("Failed to get the value of startup with err: " + err);
})
}).catch((err) => {
console.info("Failed to get the storage.")
})
```
5. Store data persistently.
......@@ -144,32 +145,32 @@ 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.");
}
storage.on('change', observer);
storage.putSync('startup', 'auto'); // Modify data in the Storage instance.
storage.flushSync(); // Trigger the StorageObserver callback.
```js
promise.then((storage) => {
var observer = function (key) {
console.info("The key of " + key + " changed.");
}
storage.on('change', observer)
storage.putSync('startup', 'auto'); // Modify data in the Storage instance.
storage.flushSync(); // Trigger the StorageObserver callback.
storage.off('change', observer); // Unsubscribe from the data changes.
}).catch((err) => {
console.info("Failed to get the storage.");
})
```
storage.off('change', observer); // Unsubscribe from the data changes.
}).catch((err) => {
console.info("Failed to get the storage.");
})
```
7. Delete the specified 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');
promise.then(() => {
console.info("Succeeded in deleting the storage.");
}).catch((err) => {
console.info("Failed to deleted the storage with err: " + err);
})
```
```js
let promise = dataStorage.deleteStorage(path + '/mystore');
promise.then(() => {
console.info("Succeeded in deleting the storage.");
}).catch((err) => {
console.info("Failed to delete the storage with err: " + err);
})
```
......@@ -3,10 +3,13 @@
Lightweight storage provides applications with data processing capability and allows applications to perform lightweight data storage and query. Data is stored in key-value (KV) pairs. Keys are of the string type, and values can be of the number, string, or Boolean type.
> **NOTE**
> **NOTE**<br/>
>
> The initial APIs of this module are supported since API version 6. Newly added APIs will be marked with a superscript to indicate their earliest API version.
> - The initial APIs of this module are supported since API version 6. Newly added APIs will be marked with a superscript to indicate their earliest API version.
>
> - The APIs of this module are no longer maintained since API Version 9. You are advised to use [`@ohos.data.preferences`](js-apis-data-preferences.md).
>
> - The APIs of this module can be used only in the FA model.
## Modules to Import
......@@ -35,15 +38,15 @@ Reads the specified file and loads its data to the **Storage** instance for data
**Parameters**
| Name | Type | Mandatory | Description |
| ---- | ------ | --------- | ------------------------ |
| path | string | Yes | Path of the target file. |
| Name| Type | Mandatory| Description |
| ------ | ------ | ---- | -------------------------- |
| path | string | Yes | Path of the target file.|
**Return value**
| Type | Description |
| ------------------- | ------------------------------------------------------ |
| [Storage](#storage) | **Storage** instance used for data storage operations. |
| Type | Description |
| ------------------- | ------------------------------------------------- |
| [Storage](#storage) | **Storage** instance used for data storage operations.|
**Example**
......@@ -53,13 +56,13 @@ import featureAbility from '@ohos.ability.featureAbility';
var path;
var context = featureAbility.getContext();
context.getFilesDir().then((filePath) => {
path = filePath;
console.info("======================>getFilesDirPromise====================>");
});
path = filePath;
console.info("======================>getFilesDirPromise====================>");
let storage = data_storage.getStorageSync(path + '/mystore');
storage.putSync('startup', 'auto');
storage.flushSync();
let storage = data_storage.getStorageSync(path + '/mystore');
storage.putSync('startup', 'auto');
storage.flushSync();
});
```
......@@ -73,10 +76,10 @@ Reads the specified file and loads its data to the **Storage** instance for data
**Parameters**
| Name | Type | Mandatory | Description |
| -------- | ---------------------------------------- | --------- | --------------------------------------------- |
| path | string | Yes | Path of the target file. |
| callback | AsyncCallback&lt;[Storage](#storage)&gt; | Yes | Callback used to return the execution result. |
| Name | Type | Mandatory| Description |
| -------- | ---------------------------------------- | ---- | -------------------------- |
| path | string | Yes | Path of the target file.|
| callback | AsyncCallback&lt;[Storage](#storage)&gt; | Yes | Callback used to return the execution result. |
**Example**
......@@ -86,18 +89,18 @@ import featureAbility from '@ohos.ability.featureAbility';
var path;
var context = featureAbility.getContext();
context.getFilesDir().then((filePath) => {
path = filePath;
console.info("======================>getFilesDirPromise====================>");
});
path = filePath;
console.info("======================>getFilesDirPromise====================>");
data_storage.getStorage(path + '/mystore', function (err, storage) {
data_storage.getStorage(path + '/mystore', function (err, storage) {
if (err) {
console.info("Failed to get the storage. path: " + path + '/mystore');
return;
console.info("Failed to get the storage. path: " + path + '/mystore');
return;
}
storage.putSync('startup', 'auto');
storage.flushSync();
})
})
});
```
......@@ -111,15 +114,15 @@ Reads the specified file and loads its data to the **Storage** instance for data
**Parameters**
| Name | Type | Mandatory | Description |
| ---- | ------ | --------- | ------------------------ |
| path | string | Yes | Path of the target file. |
| Name| Type | Mandatory| Description |
| ------ | ------ | ---- | -------------------------- |
| path | string | Yes | Path of the target file.|
**Return value**
| Type | Description |
| ---------------------------------- | ---------------------------------- |
| Promise&lt;[Storage](#storage)&gt; | Promise used to return the result. |
| Type | Description |
| ---------------------------------- | ------------------------------- |
| Promise&lt;[Storage](#storage)&gt; | Promise used to return the result.|
**Example**
......@@ -129,17 +132,17 @@ import featureAbility from '@ohos.ability.featureAbility';
var path;
var context = featureAbility.getContext();
context.getFilesDir().then((filePath) => {
path = filePath;
console.info("======================>getFilesDirPromise====================>");
});
path = filePath;
console.info("======================>getFilesDirPromise====================>");
let getPromise = data_storage.getStorage(path + '/mystore');
getPromise.then((storage) => {
let getPromise = data_storage.getStorage(path + '/mystore');
getPromise.then((storage) => {
storage.putSync('startup', 'auto');
storage.flushSync();
}).catch((err) => {
}).catch((err) => {
console.info("Failed to get the storage. path: " + path + '/mystore');
})
})
});
```
......@@ -153,9 +156,9 @@ Deletes the singleton **Storage** instance of a file from the memory, and delete
**Parameters**
| Name | Type | Mandatory | Description |
| ---- | ------ | --------- | ------------------------ |
| path | string | Yes | Path of the target file. |
| Name| Type | Mandatory| Description |
| ------ | ------ | ---- | -------------------------- |
| path | string | Yes | Path of the target file.|
**Example**
......@@ -167,12 +170,11 @@ var context = featureAbility.getContext();
context.getFilesDir().then((filePath) => {
path = filePath;
console.info("======================>getFilesDirPromise====================>");
});
data_storage.deleteStorageSync(path + '/mystore');
data_storage.deleteStorageSync(path + '/mystore');
});
```
## data_storage.deleteStorage
deleteStorage(path: string, callback: AsyncCallback&lt;void&gt;): void
......@@ -183,9 +185,9 @@ Deletes the singleton **Storage** instance of a file from the memory, and delete
**Parameters**
| Name | Type | Mandatory | Description |
| -------- | ------------------------- | --------- | ------------------------------- |
| path | string | Yes | Path of the target file. |
| Name | Type | Mandatory| Description |
| -------- | ------------------------- | ---- | -------------------------- |
| path | string | Yes | Path of the target file.|
| callback | AsyncCallback&lt;void&gt; | Yes | Callback that returns no value. |
**Example**
......@@ -196,17 +198,17 @@ import featureAbility from '@ohos.ability.featureAbility';
var path;
var context = featureAbility.getContext();
context.getFilesDir().then((filePath) => {
path = filePath;
console.info("======================>getFilesDirPromise====================>");
});
path = filePath;
console.info("======================>getFilesDirPromise====================>");
data_storage.deleteStorage(path + '/mystore', function (err) {
data_storage.deleteStorage(path + '/mystore', function (err) {
if (err) {
console.info("Failed to delete the storage with err: " + err);
return;
console.info("Failed to delete the storage with err: " + err);
return;
}
console.info("Succeeded in deleting the storage.");
})
})
});
```
......@@ -220,13 +222,14 @@ Deletes the singleton **Storage** instance of a file from the memory, and delete
**Parameters**
| Name | Type | Mandatory | Description |
| ---- | ------ | --------- | ------------------------ |
| path | string | Yes | Path of the target file. |
| Name| Type | Mandatory| Description |
| ------ | ------ | ---- | -------------------------- |
| path | string | Yes | Path of the target file.|
**Return value**
| Type | Description |
| ------------------- | ------------------------------ |
| Type | Description |
| ------------------- | ------------------------------- |
| Promise&lt;void&gt; | Promise that returns no value. |
**Example**
......@@ -237,16 +240,16 @@ import featureAbility from '@ohos.ability.featureAbility';
var path;
var context = featureAbility.getContext();
context.getFilesDir().then((filePath) => {
path = filePath;
console.info("======================>getFilesDirPromise====================>");
});
path = filePath;
console.info("======================>getFilesDirPromise====================>");
let promisedelSt = data_storage.deleteStorage(path + '/mystore');
promisedelSt.then(() => {
let promisedelSt = data_storage.deleteStorage(path + '/mystore');
promisedelSt.then(() => {
console.info("Succeeded in deleting the storage.");
}).catch((err) => {
}).catch((err) => {
console.info("Failed to delete the storage with err: " + err);
})
})
});
```
......@@ -259,10 +262,9 @@ Removes the singleton **Storage** instance of a file from the cache. The removed
**System capability**: SystemCapability.DistributedDataManager.Preferences.Core
**Parameters**
| Name | Type | Mandatory | Description |
| ---- | ------ | --------- | ------------------------ |
| path | string | Yes | Path of the target file. |
| Name| Type | Mandatory| Description |
| ------ | ------ | ---- | -------------------------- |
| path | string | Yes | Path of the target file.|
**Example**
......@@ -274,9 +276,9 @@ var context = featureAbility.getContext();
context.getFilesDir().then((filePath) => {
path = filePath;
console.info("======================>getFilesDirPromise====================>");
data_storage.removeStorageFromCacheSync(path + '/mystore');
});
data_storage.removeStorageFromCacheSync(path + '/mystore');
```
......@@ -290,9 +292,9 @@ Removes the singleton **Storage** instance of a file from the cache. The removed
**Parameters**
| Name | Type | Mandatory | Description |
| -------- | ------------------------- | --------- | ------------------------------- |
| path | string | Yes | Path of the target file. |
| Name | Type | Mandatory| Description |
| -------- | ------------------------- | ---- | -------------------------- |
| path | string | Yes | Path of the target file.|
| callback | AsyncCallback&lt;void&gt; | Yes | Callback that returns no value. |
**Example**
......@@ -303,17 +305,17 @@ import featureAbility from '@ohos.ability.featureAbility';
var path;
var context = featureAbility.getContext();
context.getFilesDir().then((filePath) => {
path = filePath;
console.info("======================>getFilesDirPromise====================>");
});
path = filePath;
console.info("======================>getFilesDirPromise====================>");
data_storage.removeStorageFromCache(path + '/mystore', function (err) {
data_storage.removeStorageFromCache(path + '/mystore', function (err) {
if (err) {
console.info("Failed to remove storage from cache with err: " + err);
return;
console.info("Failed to remove storage from cache with err: " + err);
return;
}
console.info("Succeeded in removing storage from cache.");
})
})
});
```
......@@ -327,14 +329,14 @@ Removes the singleton **Storage** instance of a file from the cache. The removed
**Parameters**
| Name | Type | Mandatory | Description |
| ---- | ------ | --------- | ------------------------ |
| path | string | Yes | Path of the target file. |
| Name| Type | Mandatory| Description |
| ------ | ------ | ---- | -------------------------- |
| path | string | Yes | Path of the target file.|
**Return value**
| Type | Description |
| ------------------- | ------------------------------ |
| Type | Description |
| ------------------- | ------------------------------- |
| Promise&lt;void&gt; | Promise that returns no value. |
**Example**
......@@ -345,24 +347,22 @@ import featureAbility from '@ohos.ability.featureAbility';
var path;
var context = featureAbility.getContext();
context.getFilesDir().then((filePath) => {
path = filePath;
console.info("======================>getFilesDirPromise====================>");
});
path = filePath;
console.info("======================>getFilesDirPromise====================>");
let promiserevSt = data_storage.removeStorageFromCache(path + '/mystore')
promiserevSt.then(() => {
let promiserevSt = data_storage.removeStorageFromCache(path + '/mystore')
promiserevSt.then(() => {
console.info("Succeeded in removing storage from cache.");
}).catch((err) => {
}).catch((err) => {
console.info("Failed to remove storage from cache with err: " + err);
})
})
});
```
## Storage
Provides APIs for obtaining and modifying storage data.
### getSync
getSync(key: string, defValue: ValueType): ValueType
......@@ -373,16 +373,16 @@ Obtains the value corresponding to a key. If the value is null or not in the def
**Parameters**
| Name | Type | Mandatory | Description |
| -------- | ----------------------- | --------- | ------------------------------------------------------------ |
| key | string | Yes | Key of the data. It cannot be empty. |
| defValue | [ValueType](#valuetype) | Yes | Default value to be returned if the value of the specified key does not exist. It can be a number, string, or Boolean value. |
| Name | Type | Mandatory| Description |
| -------- | ----------------------- | ---- | ------------------------------------------------------------ |
| key | string | Yes | Key of the data. It cannot be empty. |
| defValue | [ValueType](#valuetype) | Yes | Default value to be returned if the value of the specified key does not exist. It can be a number, string, or Boolean value.|
**Return value**
| Type | Description |
| --------- | ------------------------------------------------------------ |
| ValueType | Value corresponding to the specified key. If the value is null or not in the default value format, the default value is returned. |
| Type | Description |
| --------- | -------------------------------------------------------- |
| ValueType | Value corresponding to the specified key. If the value is null or not in the default value format, the default value is returned.|
**Example**
......@@ -402,11 +402,11 @@ Obtains the value corresponding to a key. If the value is null or not in the def
**Parameters**
| Name | Type | Mandatory | Description |
| -------- | ------------------------------ | --------- | ------------------------------------------------------------ |
| key | string | Yes | Key of the data. It cannot be empty. |
| defValue | [ValueType](#valuetype) | Yes | Default value to be returned. It can be a number, string, or Boolean value. |
| callback | AsyncCallback&lt;ValueType&gt; | Yes | Callback used to return the execution result. |
| Name | Type | Mandatory| Description |
| -------- | ------------------------------ | ---- | ----------------------------------------- |
| key | string | Yes | Key of the data. It cannot be empty. |
| defValue | [ValueType](#valuetype) | Yes | Default value to be returned. It can be a number, string, or Boolean value.|
| callback | AsyncCallback&lt;ValueType&gt; | Yes | Callback used to return the execution result. |
**Example**
......@@ -431,18 +431,19 @@ Obtains the value corresponding to a key. If the value is null or not in the def
**Parameters**
| Name | Type | Mandatory | Description |
| -------- | ----------------------- | --------- | ------------------------------------------------------------ |
| key | string | Yes | Key of the data. It cannot be empty. |
| defValue | [ValueType](#valuetype) | Yes | Default value to be returned. It can be a number, string, or Boolean value. |
| Name | Type | Mandatory| Description |
| -------- | ----------------------- | ---- | ----------------------------------------- |
| key | string | Yes | Key of the data. It cannot be empty. |
| defValue | [ValueType](#valuetype) | Yes | Default value to be returned. It can be a number, string, or Boolean value.|
**Return value**
| Type | Description |
| ------------------------ | ---------------------------------- |
| Promise&lt;ValueType&gt; | Promise used to return the result. |
| Type | Description |
| ------------------------ | ------------------------------- |
| Promise&lt;ValueType&gt; | Promise used to return the result.|
**Example**
```js
let promiseget = storage.get('startup', 'default');
promiseget.then((value) => {
......@@ -463,15 +464,15 @@ Obtains the **Storage** instance corresponding to the specified file, writes dat
**Parameters**
| Name | Type | Mandatory | Description |
| ----- | ----------------------- | --------- | ------------------------------------------------------------ |
| key | string | Yes | Key of the data. It cannot be empty. |
| value | [ValueType](#valuetype) | Yes | New value to store. It can be a number, string, or Boolean value. |
| Name| Type | Mandatory| Description |
| ------ | ----------------------- | ---- | ----------------------------------------- |
| key | string | Yes | Key of the data. It cannot be empty. |
| value | [ValueType](#valuetype) | Yes | New value to store. It can be a number, string, or Boolean value.|
**Example**
```js
storage.putSync('startup', 'auto')
storage.putSync('startup', 'auto');
```
......@@ -485,10 +486,10 @@ Obtains the **Storage** instance corresponding to the specified file, writes dat
**Parameters**
| Name | Type | Mandatory | Description |
| -------- | ------------------------- | --------- | ------------------------------------------------------------ |
| key | string | Yes | Key of the data. It cannot be empty. |
| value | [ValueType](#valuetype) | Yes | New value to store. It can be a number, string, or Boolean value. |
| Name | Type | Mandatory| Description |
| -------- | ------------------------- | ---- | ----------------------------------------- |
| key | string | Yes | Key of the data. It cannot be empty. |
| value | [ValueType](#valuetype) | Yes | New value to store. It can be a number, string, or Boolean value.|
| callback | AsyncCallback&lt;void&gt; | Yes | Callback that returns no value. |
**Example**
......@@ -514,18 +515,19 @@ Obtains the **Storage** instance corresponding to the specified file, writes dat
**Parameters**
| Name | Type | Mandatory | Description |
| ----- | ----------------------- | --------- | ------------------------------------------------------------ |
| key | string | Yes | Key of the data. It cannot be empty. |
| value | [ValueType](#valuetype) | Yes | New value to store. It can be a number, string, or Boolean value. |
| Name| Type | Mandatory| Description |
| ------ | ----------------------- | ---- | ----------------------------------------- |
| key | string | Yes | Key of the data. It cannot be empty. |
| value | [ValueType](#valuetype) | Yes | New value to store. It can be a number, string, or Boolean value.|
**Return value**
| Type | Description |
| ------------------- | ------------------------------ |
| Type | Description |
| ------------------- | --------------------------- |
| Promise&lt;void&gt; | Promise that returns no value. |
**Example**
```js
let promiseput = storage.put('startup', 'auto');
promiseput.then(() => {
......@@ -546,15 +548,15 @@ Checks whether the storage object contains data with a given key.
**Parameters**
| Name | Type | Mandatory | Description |
| ---- | ------ | --------- | ------------------------------------ |
| key | string | Yes | Key of the data. It cannot be empty. |
| Name| Type | Mandatory| Description |
| ------ | ------ | ---- | ------------------------------- |
| key | string | Yes | Key of the data. It cannot be empty.|
**Return value**
| Type | Description |
| ------- | ------------------------------------------------------------ |
| boolean | Returns **true** if the storage object contains data with the specified key; returns **false** otherwise. |
| Type | Description |
| ------- | ------------------------------------- |
| boolean | Returns **true** if the storage object contains data with the specified key; returns **false** otherwise.|
**Example**
......@@ -576,16 +578,16 @@ Checks whether the storage object contains data with a given key. This API uses
**Parameters**
| Name | Type | Mandatory | Description |
| -------- | ---------------------------- | --------- | --------------------------------------------- |
| key | string | Yes | Key of the data. It cannot be empty. |
| callback | AsyncCallback&lt;boolean&gt; | Yes | Callback used to return the execution result. |
| Name | Type | Mandatory| Description |
| -------- | ---------------------------- | ---- | ------------------------------- |
| key | string | Yes | Key of the data. It cannot be empty.|
| callback | AsyncCallback&lt;boolean&gt; | Yes | Callback used to return the execution result. |
**Return value**
| Type | Description |
| ------- | ------------------------------------------------------------ |
| boolean | Returns **true** if the storage object contains data with the specified key; returns **false** otherwise. |
| Type | Description |
| ------- | ------------------------------- |
| boolean | Returns **true** if the storage object contains data with the specified key; returns **false** otherwise.|
**Example**
......@@ -612,15 +614,15 @@ Checks whether the storage object contains data with a given key. This API uses
**Parameters**
| Name | Type | Mandatory | Description |
| ---- | ------ | --------- | ------------------------------------ |
| key | string | Yes | Key of the data. It cannot be empty. |
| Name| Type | Mandatory| Description |
| ------ | ------ | ---- | ------------------------------- |
| key | string | Yes | Key of the data. It cannot be empty.|
**Return value**
| Type | Description |
| ---------------------- | ---------------------------------- |
| Promise&lt;boolean&gt; | Promise used to return the result. |
| Type | Description |
| ---------------------- | --------------------------- |
| Promise&lt;boolean&gt; | Promise used to return the result.|
**Example**
......@@ -646,14 +648,14 @@ Deletes data with the specified key from this storage object.
**Parameters**
| Name | Type | Mandatory | Description |
| ---- | ------ | --------- | ------------------------------------ |
| key | string | Yes | Key of the data. It cannot be empty. |
| Name| Type | Mandatory| Description |
| ------ | ------ | ---- | --------------------------------- |
| key | string | Yes | Key of the data. It cannot be empty.|
**Example**
```js
storage.deleteSync('startup')
storage.deleteSync('startup');
```
......@@ -667,9 +669,9 @@ Deletes data with the specified key from this storage object. This API uses an a
**Parameters**
| Name | Type | Mandatory | Description |
| -------- | ------------------------- | --------- | ------------------------------------ |
| key | string | Yes | Key of the data. It cannot be empty. |
| Name | Type | Mandatory| Description |
| -------- | ------------------------- | ---- | ------------------------------- |
| key | string | Yes | Key of the data. It cannot be empty.|
| callback | AsyncCallback&lt;void&gt; | Yes | Callback that returns no value. |
**Example**
......@@ -695,14 +697,14 @@ Deletes data with the specified key from this storage object. This API uses a pr
**Parameters**
| Name | Type | Mandatory | Description |
| ---- | ------ | --------- | ---------------- |
| key | string | Yes | Key of the data. |
| Name| Type | Mandatory| Description |
| ------ | ------ | ---- | --------------------- |
| key | string | Yes | Key of the data.|
**Return value**
| Type | Description |
| ------------------- | ------------------------------ |
| Type | Description |
| ------------------- | --------------------------- |
| Promise&lt;void&gt; | Promise that returns no value. |
**Example**
......@@ -728,7 +730,7 @@ Saves the modification of this object to the **Storage** instance and synchroniz
**Example**
```js
storage.flushSync()
storage.flushSync();
```
......@@ -742,8 +744,8 @@ Saves the modification of this object to the **Storage** instance and synchroniz
**Parameters**
| Name | Type | Mandatory | Description |
| -------- | ------------------------- | --------- | ------------------------------- |
| Name | Type | Mandatory| Description |
| -------- | ------------------------- | ---- | ---------- |
| callback | AsyncCallback&lt;void&gt; | Yes | Callback that returns no value. |
**Example**
......@@ -769,8 +771,8 @@ Saves the modification of this object to the **Storage** instance and synchroniz
**Return value**
| Type | Description |
| ------------------- | ------------------------------ |
| Type | Description |
| ------------------- | --------------------------- |
| Promise&lt;void&gt; | Promise that returns no value. |
**Example**
......@@ -796,7 +798,7 @@ Clears this **Storage** object.
**Example**
```js
storage.clearSync()
storage.clearSync();
```
......@@ -810,8 +812,8 @@ Clears this **Storage** object. This API uses an asynchronous callback to return
**Parameters**
| Name | Type | Mandatory | Description |
| -------- | ------------------------- | --------- | ------------------------------- |
| Name | Type | Mandatory| Description |
| -------- | ------------------------- | ---- | ---------- |
| callback | AsyncCallback&lt;void&gt; | Yes | Callback that returns no value. |
**Example**
......@@ -836,9 +838,8 @@ Clears this **Storage** object. This API uses a promise to return the result.
**System capability**: SystemCapability.DistributedDataManager.Preferences.Core
**Return value**
| Type | Description |
| ------------------- | ------------------------------ |
| Type | Description |
| ------------------- | --------------------------- |
| Promise&lt;void&gt; | Promise that returns no value. |
**Example**
......@@ -863,10 +864,10 @@ Subscribes to data changes. The **StorageObserver** needs to be implemented. Whe
**Parameters**
| Name | Type | Description |
| -------- | --------------------------------------------------- | ------------------------------------------------------------ |
| type | string | Event type. The value **change** indicates data change events. |
| callback | Callback&lt;[StorageObserver](#storageobserver)&gt; | Callback used to return data changes. |
| Name | Type | Description |
| -------- | --------------------------------------------------- | ---------------------------------------- |
| type | string | Event type. The value **change** indicates data change events.|
| callback | Callback&lt;[StorageObserver](#storageobserver)&gt; | Callback used to return data changes. |
**Example**
......@@ -890,10 +891,10 @@ Unsubscribes from data changes.
**Parameters**
| Name | Type | Description |
| -------- | --------------------------------------------------- | ------------------------------------------------------------ |
| type | string | Event type. The value **change** indicates data change events. |
| callback | Callback&lt;[StorageObserver](#storageobserver)&gt; | Callback used to return data changes. |
| Name | Type | Description |
| -------- | --------------------------------------------------- | ---------------------------------------- |
| type | string | Event type. The value **change** indicates data change events.|
| callback | Callback&lt;[StorageObserver](#storageobserver)&gt; | Callback used to return data changes. |
**Example**
......@@ -909,9 +910,9 @@ storage.off('change', observer);
**System capability**: SystemCapability.DistributedDataManager.Preferences.Core
| Name | Type | Mandatory | Description |
| ---- | ------ | --------- | ------------- |
| key | string | No | Data changed. |
| Name| Type| Mandatory| Description |
| ---- | -------- | ---- | ---------------- |
| key | string | No | Data changed.|
## ValueType
......@@ -919,8 +920,8 @@ Enumerates the value types.
**System capability**: SystemCapability.DistributedDataManager.Preferences.Core
| Type | Description |
| ------- | ----------------------------- |
| number | The value is a number. |
| string | The value is a string. |
| boolean | The value is of Boolean type. |
\ No newline at end of file
| Type | Description |
| ------- | -------------------- |
| number | The value is a number. |
| string | The value is a string. |
| boolean | The value is of Boolean type.|
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册