提交 404520e7 编写于 作者: A Annie_wang

update docs

Signed-off-by: NAnnie_wang <annie.wangli@huawei.com>
上级 29f6acd4
...@@ -7,7 +7,9 @@ Lightweight storage provides applications with data processing capability and al ...@@ -7,7 +7,9 @@ Lightweight storage provides applications with data processing capability and al
> >
> - 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 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 ## Modules to Import
...@@ -36,15 +38,15 @@ Reads the specified file and loads its data to the **Storage** instance for data ...@@ -36,15 +38,15 @@ Reads the specified file and loads its data to the **Storage** instance for data
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name| Type | Mandatory| Description |
| ---- | ------ | --------- | ------------------------ | | ------ | ------ | ---- | -------------------------- |
| path | string | Yes | Path of the target file. | | path | string | Yes | Path of the target file.|
**Return value** **Return value**
| Type | Description | | Type | Description |
| ------------------- | ------------------------------------------------------ | | ------------------- | ------------------------------------------------- |
| [Storage](#storage) | **Storage** instance used for data storage operations. | | [Storage](#storage) | **Storage** instance used for data storage operations.|
**Example** **Example**
...@@ -56,11 +58,11 @@ var context = featureAbility.getContext(); ...@@ -56,11 +58,11 @@ var context = featureAbility.getContext();
context.getFilesDir().then((filePath) => { context.getFilesDir().then((filePath) => {
path = filePath; path = filePath;
console.info("======================>getFilesDirPromise====================>"); console.info("======================>getFilesDirPromise====================>");
});
let storage = data_storage.getStorageSync(path + '/mystore'); let storage = data_storage.getStorageSync(path + '/mystore');
storage.putSync('startup', 'auto'); storage.putSync('startup', 'auto');
storage.flushSync(); storage.flushSync();
});
``` ```
...@@ -74,9 +76,9 @@ Reads the specified file and loads its data to the **Storage** instance for data ...@@ -74,9 +76,9 @@ Reads the specified file and loads its data to the **Storage** instance for data
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
| -------- | ---------------------------------------- | --------- | --------------------------------------------- | | -------- | ---------------------------------------- | ---- | -------------------------- |
| path | string | Yes | Path of the target file. | | path | string | Yes | Path of the target file.|
| callback | AsyncCallback&lt;[Storage](#storage)&gt; | Yes | Callback used to return the execution result. | | callback | AsyncCallback&lt;[Storage](#storage)&gt; | Yes | Callback used to return the execution result. |
**Example** **Example**
...@@ -89,16 +91,16 @@ var context = featureAbility.getContext(); ...@@ -89,16 +91,16 @@ var context = featureAbility.getContext();
context.getFilesDir().then((filePath) => { context.getFilesDir().then((filePath) => {
path = filePath; path = filePath;
console.info("======================>getFilesDirPromise====================>"); console.info("======================>getFilesDirPromise====================>");
});
data_storage.getStorage(path + '/mystore', function (err, storage) { data_storage.getStorage(path + '/mystore', function (err, storage) {
if (err) { if (err) {
console.info("Failed to get the storage. path: " + path + '/mystore'); console.info("Failed to get the storage. path: " + path + '/mystore');
return; return;
} }
storage.putSync('startup', 'auto'); storage.putSync('startup', 'auto');
storage.flushSync(); storage.flushSync();
}) })
});
``` ```
...@@ -112,15 +114,15 @@ Reads the specified file and loads its data to the **Storage** instance for data ...@@ -112,15 +114,15 @@ Reads the specified file and loads its data to the **Storage** instance for data
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name| Type | Mandatory| Description |
| ---- | ------ | --------- | ------------------------ | | ------ | ------ | ---- | -------------------------- |
| path | string | Yes | Path of the target file. | | path | string | Yes | Path of the target file.|
**Return value** **Return value**
| Type | Description | | Type | Description |
| ---------------------------------- | ---------------------------------- | | ---------------------------------- | ------------------------------- |
| Promise&lt;[Storage](#storage)&gt; | Promise used to return the result. | | Promise&lt;[Storage](#storage)&gt; | Promise used to return the result.|
**Example** **Example**
...@@ -132,15 +134,15 @@ var context = featureAbility.getContext(); ...@@ -132,15 +134,15 @@ var context = featureAbility.getContext();
context.getFilesDir().then((filePath) => { context.getFilesDir().then((filePath) => {
path = filePath; path = filePath;
console.info("======================>getFilesDirPromise====================>"); console.info("======================>getFilesDirPromise====================>");
});
let getPromise = data_storage.getStorage(path + '/mystore'); let getPromise = data_storage.getStorage(path + '/mystore');
getPromise.then((storage) => { getPromise.then((storage) => {
storage.putSync('startup', 'auto'); storage.putSync('startup', 'auto');
storage.flushSync(); storage.flushSync();
}).catch((err) => { }).catch((err) => {
console.info("Failed to get the storage. path: " + path + '/mystore'); console.info("Failed to get the storage. path: " + path + '/mystore');
}) })
});
``` ```
...@@ -154,9 +156,9 @@ Deletes the singleton **Storage** instance of a file from the memory, and delete ...@@ -154,9 +156,9 @@ Deletes the singleton **Storage** instance of a file from the memory, and delete
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name| Type | Mandatory| Description |
| ---- | ------ | --------- | ------------------------ | | ------ | ------ | ---- | -------------------------- |
| path | string | Yes | Path of the target file. | | path | string | Yes | Path of the target file.|
**Example** **Example**
...@@ -168,12 +170,11 @@ var context = featureAbility.getContext(); ...@@ -168,12 +170,11 @@ var context = featureAbility.getContext();
context.getFilesDir().then((filePath) => { context.getFilesDir().then((filePath) => {
path = filePath; path = filePath;
console.info("======================>getFilesDirPromise====================>"); console.info("======================>getFilesDirPromise====================>");
});
data_storage.deleteStorageSync(path + '/mystore'); data_storage.deleteStorageSync(path + '/mystore');
});
``` ```
## data_storage.deleteStorage ## data_storage.deleteStorage
deleteStorage(path: string, callback: AsyncCallback&lt;void&gt;): void deleteStorage(path: string, callback: AsyncCallback&lt;void&gt;): void
...@@ -184,9 +185,9 @@ Deletes the singleton **Storage** instance of a file from the memory, and delete ...@@ -184,9 +185,9 @@ Deletes the singleton **Storage** instance of a file from the memory, and delete
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
| -------- | ------------------------- | --------- | ------------------------------- | | -------- | ------------------------- | ---- | -------------------------- |
| path | string | Yes | Path of the target file. | | path | string | Yes | Path of the target file.|
| callback | AsyncCallback&lt;void&gt; | Yes | Callback that returns no value. | | callback | AsyncCallback&lt;void&gt; | Yes | Callback that returns no value. |
**Example** **Example**
...@@ -199,15 +200,15 @@ var context = featureAbility.getContext(); ...@@ -199,15 +200,15 @@ var context = featureAbility.getContext();
context.getFilesDir().then((filePath) => { context.getFilesDir().then((filePath) => {
path = filePath; path = filePath;
console.info("======================>getFilesDirPromise====================>"); console.info("======================>getFilesDirPromise====================>");
});
data_storage.deleteStorage(path + '/mystore', function (err) { data_storage.deleteStorage(path + '/mystore', function (err) {
if (err) { if (err) {
console.info("Failed to delete the storage with err: " + err); console.info("Failed to delete the storage with err: " + err);
return; return;
} }
console.info("Succeeded in deleting the storage."); console.info("Succeeded in deleting the storage.");
}) })
});
``` ```
...@@ -221,13 +222,14 @@ Deletes the singleton **Storage** instance of a file from the memory, and delete ...@@ -221,13 +222,14 @@ Deletes the singleton **Storage** instance of a file from the memory, and delete
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name| Type | Mandatory| Description |
| ---- | ------ | --------- | ------------------------ | | ------ | ------ | ---- | -------------------------- |
| path | string | Yes | Path of the target file. | | path | string | Yes | Path of the target file.|
**Return value** **Return value**
| Type | Description | | Type | Description |
| ------------------- | ------------------------------ | | ------------------- | ------------------------------- |
| Promise&lt;void&gt; | Promise that returns no value. | | Promise&lt;void&gt; | Promise that returns no value. |
**Example** **Example**
...@@ -240,14 +242,14 @@ var context = featureAbility.getContext(); ...@@ -240,14 +242,14 @@ var context = featureAbility.getContext();
context.getFilesDir().then((filePath) => { context.getFilesDir().then((filePath) => {
path = filePath; path = filePath;
console.info("======================>getFilesDirPromise====================>"); console.info("======================>getFilesDirPromise====================>");
});
let promisedelSt = data_storage.deleteStorage(path + '/mystore'); let promisedelSt = data_storage.deleteStorage(path + '/mystore');
promisedelSt.then(() => { promisedelSt.then(() => {
console.info("Succeeded in deleting the storage."); console.info("Succeeded in deleting the storage.");
}).catch((err) => { }).catch((err) => {
console.info("Failed to delete the storage with err: " + err); console.info("Failed to delete the storage with err: " + err);
}) })
});
``` ```
...@@ -260,10 +262,9 @@ Removes the singleton **Storage** instance of a file from the cache. The removed ...@@ -260,10 +262,9 @@ Removes the singleton **Storage** instance of a file from the cache. The removed
**System capability**: SystemCapability.DistributedDataManager.Preferences.Core **System capability**: SystemCapability.DistributedDataManager.Preferences.Core
**Parameters** **Parameters**
| Name| Type | Mandatory| Description |
| Name | Type | Mandatory | Description | | ------ | ------ | ---- | -------------------------- |
| ---- | ------ | --------- | ------------------------ | | path | string | Yes | Path of the target file.|
| path | string | Yes | Path of the target file. |
**Example** **Example**
...@@ -275,9 +276,9 @@ var context = featureAbility.getContext(); ...@@ -275,9 +276,9 @@ var context = featureAbility.getContext();
context.getFilesDir().then((filePath) => { context.getFilesDir().then((filePath) => {
path = filePath; path = filePath;
console.info("======================>getFilesDirPromise====================>"); console.info("======================>getFilesDirPromise====================>");
});
data_storage.removeStorageFromCacheSync(path + '/mystore'); data_storage.removeStorageFromCacheSync(path + '/mystore');
});
``` ```
...@@ -291,9 +292,9 @@ Removes the singleton **Storage** instance of a file from the cache. The removed ...@@ -291,9 +292,9 @@ Removes the singleton **Storage** instance of a file from the cache. The removed
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
| -------- | ------------------------- | --------- | ------------------------------- | | -------- | ------------------------- | ---- | -------------------------- |
| path | string | Yes | Path of the target file. | | path | string | Yes | Path of the target file.|
| callback | AsyncCallback&lt;void&gt; | Yes | Callback that returns no value. | | callback | AsyncCallback&lt;void&gt; | Yes | Callback that returns no value. |
**Example** **Example**
...@@ -306,15 +307,15 @@ var context = featureAbility.getContext(); ...@@ -306,15 +307,15 @@ var context = featureAbility.getContext();
context.getFilesDir().then((filePath) => { context.getFilesDir().then((filePath) => {
path = filePath; path = filePath;
console.info("======================>getFilesDirPromise====================>"); console.info("======================>getFilesDirPromise====================>");
});
data_storage.removeStorageFromCache(path + '/mystore', function (err) { data_storage.removeStorageFromCache(path + '/mystore', function (err) {
if (err) { if (err) {
console.info("Failed to remove storage from cache with err: " + err); console.info("Failed to remove storage from cache with err: " + err);
return; return;
} }
console.info("Succeeded in removing storage from cache."); console.info("Succeeded in removing storage from cache.");
}) })
});
``` ```
...@@ -328,14 +329,14 @@ Removes the singleton **Storage** instance of a file from the cache. The removed ...@@ -328,14 +329,14 @@ Removes the singleton **Storage** instance of a file from the cache. The removed
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name| Type | Mandatory| Description |
| ---- | ------ | --------- | ------------------------ | | ------ | ------ | ---- | -------------------------- |
| path | string | Yes | Path of the target file. | | path | string | Yes | Path of the target file.|
**Return value** **Return value**
| Type | Description | | Type | Description |
| ------------------- | ------------------------------ | | ------------------- | ------------------------------- |
| Promise&lt;void&gt; | Promise that returns no value. | | Promise&lt;void&gt; | Promise that returns no value. |
**Example** **Example**
...@@ -348,22 +349,20 @@ var context = featureAbility.getContext(); ...@@ -348,22 +349,20 @@ var context = featureAbility.getContext();
context.getFilesDir().then((filePath) => { context.getFilesDir().then((filePath) => {
path = filePath; path = filePath;
console.info("======================>getFilesDirPromise====================>"); console.info("======================>getFilesDirPromise====================>");
});
let promiserevSt = data_storage.removeStorageFromCache(path + '/mystore') let promiserevSt = data_storage.removeStorageFromCache(path + '/mystore')
promiserevSt.then(() => { promiserevSt.then(() => {
console.info("Succeeded in removing storage from cache."); console.info("Succeeded in removing storage from cache.");
}).catch((err) => { }).catch((err) => {
console.info("Failed to remove storage from cache with err: " + err); console.info("Failed to remove storage from cache with err: " + err);
}) })
});
``` ```
## Storage ## Storage
Provides APIs for obtaining and modifying storage data. Provides APIs for obtaining and modifying storage data.
### getSync ### getSync
getSync(key: string, defValue: ValueType): ValueType getSync(key: string, defValue: ValueType): ValueType
...@@ -374,16 +373,16 @@ Obtains the value corresponding to a key. If the value is null or not in the def ...@@ -374,16 +373,16 @@ Obtains the value corresponding to a key. If the value is null or not in the def
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
| -------- | ----------------------- | --------- | ------------------------------------------------------------ | | -------- | ----------------------- | ---- | ------------------------------------------------------------ |
| key | string | Yes | Key of the data. It cannot be empty. | | 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. | | 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** **Return value**
| Type | Description | | 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. | | 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** **Example**
...@@ -403,10 +402,10 @@ Obtains the value corresponding to a key. If the value is null or not in the def ...@@ -403,10 +402,10 @@ Obtains the value corresponding to a key. If the value is null or not in the def
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
| -------- | ------------------------------ | --------- | ------------------------------------------------------------ | | -------- | ------------------------------ | ---- | ----------------------------------------- |
| key | string | Yes | Key of the data. It cannot be empty. | | 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. | | 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. | | callback | AsyncCallback&lt;ValueType&gt; | Yes | Callback used to return the execution result. |
**Example** **Example**
...@@ -432,18 +431,19 @@ Obtains the value corresponding to a key. If the value is null or not in the def ...@@ -432,18 +431,19 @@ Obtains the value corresponding to a key. If the value is null or not in the def
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
| -------- | ----------------------- | --------- | ------------------------------------------------------------ | | -------- | ----------------------- | ---- | ----------------------------------------- |
| key | string | Yes | Key of the data. It cannot be empty. | | 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. | | defValue | [ValueType](#valuetype) | Yes | Default value to be returned. It can be a number, string, or Boolean value.|
**Return value** **Return value**
| Type | Description | | Type | Description |
| ------------------------ | ---------------------------------- | | ------------------------ | ------------------------------- |
| Promise&lt;ValueType&gt; | Promise used to return the result. | | Promise&lt;ValueType&gt; | Promise used to return the result.|
**Example** **Example**
```js ```js
let promiseget = storage.get('startup', 'default'); let promiseget = storage.get('startup', 'default');
promiseget.then((value) => { promiseget.then((value) => {
...@@ -464,15 +464,15 @@ Obtains the **Storage** instance corresponding to the specified file, writes dat ...@@ -464,15 +464,15 @@ Obtains the **Storage** instance corresponding to the specified file, writes dat
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name| Type | Mandatory| Description |
| ----- | ----------------------- | --------- | ------------------------------------------------------------ | | ------ | ----------------------- | ---- | ----------------------------------------- |
| key | string | Yes | Key of the data. It cannot be empty. | | 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. | | value | [ValueType](#valuetype) | Yes | New value to store. It can be a number, string, or Boolean value.|
**Example** **Example**
```js ```js
storage.putSync('startup', 'auto') storage.putSync('startup', 'auto');
``` ```
...@@ -486,10 +486,10 @@ Obtains the **Storage** instance corresponding to the specified file, writes dat ...@@ -486,10 +486,10 @@ Obtains the **Storage** instance corresponding to the specified file, writes dat
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
| -------- | ------------------------- | --------- | ------------------------------------------------------------ | | -------- | ------------------------- | ---- | ----------------------------------------- |
| key | string | Yes | Key of the data. It cannot be empty. | | 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. | | 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. | | callback | AsyncCallback&lt;void&gt; | Yes | Callback that returns no value. |
**Example** **Example**
...@@ -515,18 +515,19 @@ Obtains the **Storage** instance corresponding to the specified file, writes dat ...@@ -515,18 +515,19 @@ Obtains the **Storage** instance corresponding to the specified file, writes dat
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name| Type | Mandatory| Description |
| ----- | ----------------------- | --------- | ------------------------------------------------------------ | | ------ | ----------------------- | ---- | ----------------------------------------- |
| key | string | Yes | Key of the data. It cannot be empty. | | 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. | | value | [ValueType](#valuetype) | Yes | New value to store. It can be a number, string, or Boolean value.|
**Return value** **Return value**
| Type | Description | | Type | Description |
| ------------------- | ------------------------------ | | ------------------- | --------------------------- |
| Promise&lt;void&gt; | Promise that returns no value. | | Promise&lt;void&gt; | Promise that returns no value. |
**Example** **Example**
```js ```js
let promiseput = storage.put('startup', 'auto'); let promiseput = storage.put('startup', 'auto');
promiseput.then(() => { promiseput.then(() => {
...@@ -547,15 +548,15 @@ Checks whether the storage object contains data with a given key. ...@@ -547,15 +548,15 @@ Checks whether the storage object contains data with a given key.
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name| Type | Mandatory| Description |
| ---- | ------ | --------- | ------------------------------------ | | ------ | ------ | ---- | ------------------------------- |
| key | string | Yes | Key of the data. It cannot be empty. | | key | string | Yes | Key of the data. It cannot be empty.|
**Return value** **Return value**
| Type | Description | | Type | Description |
| ------- | ------------------------------------------------------------ | | ------- | ------------------------------------- |
| boolean | Returns **true** if the storage object contains data with the specified key; returns **false** otherwise. | | boolean | Returns **true** if the storage object contains data with the specified key; returns **false** otherwise.|
**Example** **Example**
...@@ -577,16 +578,16 @@ Checks whether the storage object contains data with a given key. This API uses ...@@ -577,16 +578,16 @@ Checks whether the storage object contains data with a given key. This API uses
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
| -------- | ---------------------------- | --------- | --------------------------------------------- | | -------- | ---------------------------- | ---- | ------------------------------- |
| key | string | Yes | Key of the data. It cannot be empty. | | key | string | Yes | Key of the data. It cannot be empty.|
| callback | AsyncCallback&lt;boolean&gt; | Yes | Callback used to return the execution result. | | callback | AsyncCallback&lt;boolean&gt; | Yes | Callback used to return the execution result. |
**Return value** **Return value**
| Type | Description | | Type | Description |
| ------- | ------------------------------------------------------------ | | ------- | ------------------------------- |
| boolean | Returns **true** if the storage object contains data with the specified key; returns **false** otherwise. | | boolean | Returns **true** if the storage object contains data with the specified key; returns **false** otherwise.|
**Example** **Example**
...@@ -613,15 +614,15 @@ Checks whether the storage object contains data with a given key. This API uses ...@@ -613,15 +614,15 @@ Checks whether the storage object contains data with a given key. This API uses
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name| Type | Mandatory| Description |
| ---- | ------ | --------- | ------------------------------------ | | ------ | ------ | ---- | ------------------------------- |
| key | string | Yes | Key of the data. It cannot be empty. | | key | string | Yes | Key of the data. It cannot be empty.|
**Return value** **Return value**
| Type | Description | | Type | Description |
| ---------------------- | ---------------------------------- | | ---------------------- | --------------------------- |
| Promise&lt;boolean&gt; | Promise used to return the result. | | Promise&lt;boolean&gt; | Promise used to return the result.|
**Example** **Example**
...@@ -647,14 +648,14 @@ Deletes data with the specified key from this storage object. ...@@ -647,14 +648,14 @@ Deletes data with the specified key from this storage object.
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name| Type | Mandatory| Description |
| ---- | ------ | --------- | ------------------------------------ | | ------ | ------ | ---- | --------------------------------- |
| key | string | Yes | Key of the data. It cannot be empty. | | key | string | Yes | Key of the data. It cannot be empty.|
**Example** **Example**
```js ```js
storage.deleteSync('startup') storage.deleteSync('startup');
``` ```
...@@ -668,9 +669,9 @@ Deletes data with the specified key from this storage object. This API uses an a ...@@ -668,9 +669,9 @@ Deletes data with the specified key from this storage object. This API uses an a
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
| -------- | ------------------------- | --------- | ------------------------------------ | | -------- | ------------------------- | ---- | ------------------------------- |
| key | string | Yes | Key of the data. It cannot be empty. | | key | string | Yes | Key of the data. It cannot be empty.|
| callback | AsyncCallback&lt;void&gt; | Yes | Callback that returns no value. | | callback | AsyncCallback&lt;void&gt; | Yes | Callback that returns no value. |
**Example** **Example**
...@@ -696,14 +697,14 @@ Deletes data with the specified key from this storage object. This API uses a pr ...@@ -696,14 +697,14 @@ Deletes data with the specified key from this storage object. This API uses a pr
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name| Type | Mandatory| Description |
| ---- | ------ | --------- | ---------------- | | ------ | ------ | ---- | --------------------- |
| key | string | Yes | Key of the data. | | key | string | Yes | Key of the data.|
**Return value** **Return value**
| Type | Description | | Type | Description |
| ------------------- | ------------------------------ | | ------------------- | --------------------------- |
| Promise&lt;void&gt; | Promise that returns no value. | | Promise&lt;void&gt; | Promise that returns no value. |
**Example** **Example**
...@@ -729,7 +730,7 @@ Saves the modification of this object to the **Storage** instance and synchroniz ...@@ -729,7 +730,7 @@ Saves the modification of this object to the **Storage** instance and synchroniz
**Example** **Example**
```js ```js
storage.flushSync() storage.flushSync();
``` ```
...@@ -743,8 +744,8 @@ Saves the modification of this object to the **Storage** instance and synchroniz ...@@ -743,8 +744,8 @@ Saves the modification of this object to the **Storage** instance and synchroniz
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
| -------- | ------------------------- | --------- | ------------------------------- | | -------- | ------------------------- | ---- | ---------- |
| callback | AsyncCallback&lt;void&gt; | Yes | Callback that returns no value. | | callback | AsyncCallback&lt;void&gt; | Yes | Callback that returns no value. |
**Example** **Example**
...@@ -771,7 +772,7 @@ Saves the modification of this object to the **Storage** instance and synchroniz ...@@ -771,7 +772,7 @@ Saves the modification of this object to the **Storage** instance and synchroniz
**Return value** **Return value**
| Type | Description | | Type | Description |
| ------------------- | ------------------------------ | | ------------------- | --------------------------- |
| Promise&lt;void&gt; | Promise that returns no value. | | Promise&lt;void&gt; | Promise that returns no value. |
**Example** **Example**
...@@ -797,7 +798,7 @@ Clears this **Storage** object. ...@@ -797,7 +798,7 @@ Clears this **Storage** object.
**Example** **Example**
```js ```js
storage.clearSync() storage.clearSync();
``` ```
...@@ -811,8 +812,8 @@ Clears this **Storage** object. This API uses an asynchronous callback to return ...@@ -811,8 +812,8 @@ Clears this **Storage** object. This API uses an asynchronous callback to return
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
| -------- | ------------------------- | --------- | ------------------------------- | | -------- | ------------------------- | ---- | ---------- |
| callback | AsyncCallback&lt;void&gt; | Yes | Callback that returns no value. | | callback | AsyncCallback&lt;void&gt; | Yes | Callback that returns no value. |
**Example** **Example**
...@@ -837,9 +838,8 @@ Clears this **Storage** object. This API uses a promise to return the result. ...@@ -837,9 +838,8 @@ Clears this **Storage** object. This API uses a promise to return the result.
**System capability**: SystemCapability.DistributedDataManager.Preferences.Core **System capability**: SystemCapability.DistributedDataManager.Preferences.Core
**Return value** **Return value**
| Type | Description | | Type | Description |
| ------------------- | ------------------------------ | | ------------------- | --------------------------- |
| Promise&lt;void&gt; | Promise that returns no value. | | Promise&lt;void&gt; | Promise that returns no value. |
**Example** **Example**
...@@ -865,8 +865,8 @@ Subscribes to data changes. The **StorageObserver** needs to be implemented. Whe ...@@ -865,8 +865,8 @@ Subscribes to data changes. The **StorageObserver** needs to be implemented. Whe
**Parameters** **Parameters**
| Name | Type | Description | | Name | Type | Description |
| -------- | --------------------------------------------------- | ------------------------------------------------------------ | | -------- | --------------------------------------------------- | ---------------------------------------- |
| type | string | Event type. The value **change** indicates data change events. | | type | string | Event type. The value **change** indicates data change events.|
| callback | Callback&lt;[StorageObserver](#storageobserver)&gt; | Callback used to return data changes. | | callback | Callback&lt;[StorageObserver](#storageobserver)&gt; | Callback used to return data changes. |
**Example** **Example**
...@@ -892,8 +892,8 @@ Unsubscribes from data changes. ...@@ -892,8 +892,8 @@ Unsubscribes from data changes.
**Parameters** **Parameters**
| Name | Type | Description | | Name | Type | Description |
| -------- | --------------------------------------------------- | ------------------------------------------------------------ | | -------- | --------------------------------------------------- | ---------------------------------------- |
| type | string | Event type. The value **change** indicates data change events. | | type | string | Event type. The value **change** indicates data change events.|
| callback | Callback&lt;[StorageObserver](#storageobserver)&gt; | Callback used to return data changes. | | callback | Callback&lt;[StorageObserver](#storageobserver)&gt; | Callback used to return data changes. |
**Example** **Example**
...@@ -910,9 +910,9 @@ storage.off('change', observer); ...@@ -910,9 +910,9 @@ storage.off('change', observer);
**System capability**: SystemCapability.DistributedDataManager.Preferences.Core **System capability**: SystemCapability.DistributedDataManager.Preferences.Core
| Name | Type | Mandatory | Description | | Name| Type| Mandatory| Description |
| ---- | ------ | --------- | ------------- | | ---- | -------- | ---- | ---------------- |
| key | string | No | Data changed. | | key | string | No | Data changed.|
## ValueType ## ValueType
...@@ -921,7 +921,7 @@ Enumerates the value types. ...@@ -921,7 +921,7 @@ Enumerates the value types.
**System capability**: SystemCapability.DistributedDataManager.Preferences.Core **System capability**: SystemCapability.DistributedDataManager.Preferences.Core
| Type | Description | | Type | Description |
| ------- | ----------------------------- | | ------- | -------------------- |
| number | The value is a number. | | number | The value is a number. |
| string | The value is a string. | | string | The value is a string. |
| boolean | The value is of Boolean type. | | boolean | The value is of Boolean type.|
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册