未验证 提交 1e34c998 编写于 作者: O openharmony_ci 提交者: Gitee

!5360 【翻译完成】#I59QKJ

Merge pull request !5360 from Annie_wang/PR4553
...@@ -33,11 +33,11 @@ Reads a **Preferences** persistence file and loads data to the **Preferences** i ...@@ -33,11 +33,11 @@ Reads a **Preferences** persistence file and loads data to the **Preferences** i
**System capability**: SystemCapability.DistributedDataManager.Preferences.Core **System capability**: SystemCapability.DistributedDataManager.Preferences.Core
**Parameters** **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| context | [Context](js-apis-ability-context.md) | Yes| Context of the application or functionality.| | context | [Context](js-apis-ability-context.md) | Yes| Context of the application or functionality.|
| name | string | Yes| Name of the **Preferences** instance persistence file.| | name | string | Yes| Name of the **Preferences** instance persistence file.|
| callback | AsyncCallback<[Preferences](#preferences)> | Yes| Callback used to return the result.| | callback | AsyncCallback<[Preferences](#preferences)> | Yes| Callback used to return the result.|
**Example** **Example**
```ts ```ts
...@@ -60,15 +60,15 @@ Reads a **Preferences** persistence file and loads data to the **Preferences** i ...@@ -60,15 +60,15 @@ Reads a **Preferences** persistence file and loads data to the **Preferences** i
**System capability**: SystemCapability.DistributedDataManager.Preferences.Core **System capability**: SystemCapability.DistributedDataManager.Preferences.Core
**Parameters** **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| context | [Context](js-apis-ability-context.md) | Yes| Context of the application or functionality.| | context | [Context](js-apis-ability-context.md) | Yes| Context of the application or functionality.|
| name | string | Yes| Name of the **Preferences** instance persistence file.| | name | string | Yes| Name of the **Preferences** instance persistence file.|
**Return value** **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| Promise<[Preferences](#preferences)> | Promise used to return the result.| | Promise<[Preferences](#preferences)> | Promise used to return the result.|
**Example** **Example**
```ts ```ts
...@@ -76,7 +76,7 @@ let promise = data_preferences.getPreferences(this.context, 'mystore') ...@@ -76,7 +76,7 @@ let promise = data_preferences.getPreferences(this.context, 'mystore')
promise.then((preferences) => { promise.then((preferences) => {
console.info("Got preferences successfully.") console.info("Got preferences successfully.")
}).catch((err) => { }).catch((err) => {
console.info("Failed to get the preferences") console.info("Failed to get the preferences")
}) })
``` ```
...@@ -91,11 +91,11 @@ Once a **Preferences** persistence file is deleted, the **Preferences** instance ...@@ -91,11 +91,11 @@ Once a **Preferences** persistence file is deleted, the **Preferences** instance
**System capability**: SystemCapability.DistributedDataManager.Preferences.Core **System capability**: SystemCapability.DistributedDataManager.Preferences.Core
**Parameters** **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| context | [Context](js-apis-ability-context.md) | Yes| Context of the application or functionality.| | context | [Context](js-apis-ability-context.md) | Yes| Context of the application or functionality.|
| name | string | Yes| Name of the **Preferences** instance persistence file.| | name | string | Yes| Name of the **Preferences** instance persistence file.|
| callback | AsyncCallback<void> | Yes| Callback used to return the result.| | callback | AsyncCallback<void> | Yes| Callback used to return the result.|
**Example** **Example**
```ts ```ts
...@@ -119,15 +119,15 @@ Once a **Preferences** persistence file is deleted, the **Preferences** instance ...@@ -119,15 +119,15 @@ Once a **Preferences** persistence file is deleted, the **Preferences** instance
**System capability**: SystemCapability.DistributedDataManager.Preferences.Core **System capability**: SystemCapability.DistributedDataManager.Preferences.Core
**Parameters** **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| context | [Context](js-apis-ability-context.md) | Yes| Context of the application or functionality.| | context | [Context](js-apis-ability-context.md) | Yes| Context of the application or functionality.|
| name | string | Yes| Name of the **Preferences** instance persistence file.| | name | string | Yes| Name of the **Preferences** instance persistence file.|
**Return value** **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| Promise<void> | Promise used to return the result.| | Promise<void> | Promise used to return the result.|
**Example** **Example**
```ts ```ts
...@@ -151,11 +151,11 @@ When a **Preferences** singleton instance is removed, this instance cannot be us ...@@ -151,11 +151,11 @@ When a **Preferences** singleton instance is removed, this instance cannot be us
**System capability**: SystemCapability.DistributedDataManager.Preferences.Core **System capability**: SystemCapability.DistributedDataManager.Preferences.Core
**Parameters** **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| context | [Context](js-apis-ability-context.md) | Yes| Context of the application or functionality.| | context | [Context](js-apis-ability-context.md) | Yes| Context of the application or functionality.|
| name | string | Yes| Name of the **Preferences** instance persistence file.| | name | string | Yes| Name of the **Preferences** instance persistence file.|
| callback | AsyncCallback<void> | Yes| Callback used to return the result.| | callback | AsyncCallback<void> | Yes| Callback used to return the result.|
**Example** **Example**
```ts ```ts
...@@ -179,16 +179,16 @@ When a **Preferences** singleton instance is removed, this instance cannot be us ...@@ -179,16 +179,16 @@ When a **Preferences** singleton instance is removed, this instance cannot be us
**System capability**: SystemCapability.DistributedDataManager.Preferences.Core **System capability**: SystemCapability.DistributedDataManager.Preferences.Core
Parameters **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| context | [Context](js-apis-ability-context.md) | Yes| Context of the application or functionality.| | context | [Context](js-apis-ability-context.md) | Yes| Context of the application or functionality.|
| name | string | Yes| Name of the **Preferences** instance persistence file.| | name | string | Yes| Name of the **Preferences** instance persistence file.|
**Return value** **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| Promise<void> | Promise used to return the result.| | Promise<void> | Promise used to return the result.|
**Example** **Example**
```ts ```ts
...@@ -215,15 +215,15 @@ Obtains the value of a key. If the value is null or a non-default value, the def ...@@ -215,15 +215,15 @@ Obtains the value of a key. If the value is null or a non-default value, the def
**System capability**: SystemCapability.DistributedDataManager.Preferences.Core **System capability**: SystemCapability.DistributedDataManager.Preferences.Core
**Parameters** **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| key | string | Yes| Key of the data to obtain. It cannot be empty.| | key | string | Yes| Key of the data to obtain. 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<ValueType> | Yes| Callback used to return the result.| | callback | AsyncCallback<ValueType> | Yes| Callback used to return the result.|
**Example** **Example**
```ts ```ts
preferences.get('startup', 'default', function(err, value) { preferences.get('startup', 'default', function(err, value) {
if (err) { if (err) {
console.info("Failed to get the value of startup, err: " + err) console.info("Failed to get the value of startup, err: " + err)
return return
...@@ -242,15 +242,15 @@ Obtains the value of a key. If the value is null or a non-default value, the def ...@@ -242,15 +242,15 @@ Obtains the value of a key. If the value is null or a non-default value, the def
**System capability**: SystemCapability.DistributedDataManager.Preferences.Core **System capability**: SystemCapability.DistributedDataManager.Preferences.Core
**Parameters** **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| key | string | Yes| Key of the data to obtain. It cannot be empty.| | key | string | Yes| Key of the data to obtain. 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<ValueType> | Promise used to return the result.| | Promise<ValueType> | Promise used to return the result.|
**Example** **Example**
```ts ```ts
...@@ -270,10 +270,10 @@ Obtains the **Object** instance that contains all KV pairs. ...@@ -270,10 +270,10 @@ Obtains the **Object** instance that contains all KV pairs.
**System capability**: SystemCapability.DistributedDataManager.Preferences.Core **System capability**: SystemCapability.DistributedDataManager.Preferences.Core
Parameters **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| callback | AsyncCallback<Object> | Yes| Callback used to return the **Object** instance that contains all KV pairs. | | callback | AsyncCallback<Object> | Yes| Callback used to return the **Object** instance obtained.|
**Example** **Example**
```ts ```ts
...@@ -288,6 +288,7 @@ preferences.get.getAll(function (err, value) { ...@@ -288,6 +288,7 @@ preferences.get.getAll(function (err, value) {
}); });
``` ```
### getAll ### getAll
getAll(): Promise<Object> getAll(): Promise<Object>
...@@ -299,7 +300,7 @@ Obtains the **Object** instance that contains all KV pairs. ...@@ -299,7 +300,7 @@ Obtains the **Object** instance that contains all KV pairs.
**Return value** **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| Promise<Object> | Promise used to return the **Object** instance that contains all KV pairs. | | Promise<Object> | Promise used to return the **Object** instance obtained.|
**Example** **Example**
```ts ```ts
...@@ -322,11 +323,11 @@ Puts a new value to this **Preferences** instance and its persistence file. This ...@@ -322,11 +323,11 @@ Puts a new value to this **Preferences** instance and its persistence file. This
**System capability**: SystemCapability.DistributedDataManager.Preferences.Core **System capability**: SystemCapability.DistributedDataManager.Preferences.Core
**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<void> | Yes| Callback used to return the result.| | callback | AsyncCallback<void> | Yes| Callback used to return the result.|
**Example** **Example**
```ts ```ts
...@@ -339,6 +340,7 @@ preferences.put('startup', 'auto', function (err) { ...@@ -339,6 +340,7 @@ preferences.put('startup', 'auto', function (err) {
}) })
``` ```
### put ### put
put(key: string, value: ValueType): Promise<void> put(key: string, value: ValueType): Promise<void>
...@@ -348,15 +350,15 @@ Puts a new value to this **Preferences** instance and its persistence file. This ...@@ -348,15 +350,15 @@ Puts a new value to this **Preferences** instance and its persistence file. This
**System capability**: SystemCapability.DistributedDataManager.Preferences.Core **System capability**: SystemCapability.DistributedDataManager.Preferences.Core
**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<void> | Promise used to return the result.| | Promise<void> | Promise used to return the result.|
**Example** **Example**
```ts ```ts
...@@ -378,11 +380,10 @@ Checks whether this **Preferences** instance contains data with a given key. Thi ...@@ -378,11 +380,10 @@ Checks whether this **Preferences** instance contains data with a given key. Thi
**System capability**: SystemCapability.DistributedDataManager.Preferences.Core **System capability**: SystemCapability.DistributedDataManager.Preferences.Core
**Parameters** **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| key | string | Yes| Key of the data to check. It cannot be empty.| | key | string | Yes| Key of the data to check. It cannot be empty.|
| callback | AsyncCallback<boolean> | Yes| Callback used to return the result. It returns **true** if the **Preferences** instance contains data with the given key and returns **false** otherwise.| | callback | AsyncCallback<boolean> | Yes| Callback used to return the result. It returns **true** if the **Preferences** instance contains data with the given key and returns **false** otherwise.|
**Example** **Example**
```ts ```ts
...@@ -409,14 +410,14 @@ Checks whether this **Preferences** instance contains data with a given key. Thi ...@@ -409,14 +410,14 @@ Checks whether this **Preferences** instance contains data with a given key. Thi
**System capability**: SystemCapability.DistributedDataManager.Preferences.Core **System capability**: SystemCapability.DistributedDataManager.Preferences.Core
**Parameters** **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| key | string | Yes| Key of the data to check. It cannot be empty.| | key | string | Yes| Key of the data to check. It cannot be empty.|
**Return value** **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| Promise<boolean> | Promise used to return the result. It returns **true** if the **Preferences** instance contains data with the given key and returns **false** otherwise.| | Promise<boolean> | Promise used to return the result. It returns **true** if the **Preferences** instance contains data with the given key and returns **false** otherwise.|
**Example** **Example**
```ts ```ts
...@@ -428,7 +429,7 @@ promise.then((isExist) => { ...@@ -428,7 +429,7 @@ promise.then((isExist) => {
console.info("The key of startup is not contained.") console.info("The key of startup is not contained.")
} }
}).catch((err) => { }).catch((err) => {
console.info("Check the key of startup failed, err: " + err) console.info("Failed to check the key of startup, err: " + err)
}) })
``` ```
...@@ -442,10 +443,10 @@ Deletes a KV pair of the specified key from this **Preferences** instance. This ...@@ -442,10 +443,10 @@ Deletes a KV pair of the specified key from this **Preferences** instance. This
**System capability**: SystemCapability.DistributedDataManager.Preferences.Core **System capability**: SystemCapability.DistributedDataManager.Preferences.Core
**Parameters** **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| key | string | Yes| Key of the KV pair to delete. It cannot be empty.| | key | string | Yes| Key of the KV pair to delete. It cannot be empty.|
| callback | AsyncCallback<void> | Yes| Callback used to return the result.| | callback | AsyncCallback<void> | Yes| Callback used to return the result.|
**Example** **Example**
```ts ```ts
...@@ -468,14 +469,14 @@ Deletes a KV pair of the specified key from this **Preferences** instance. This ...@@ -468,14 +469,14 @@ Deletes a KV pair of the specified key from this **Preferences** instance. This
**System capability**: SystemCapability.DistributedDataManager.Preferences.Core **System capability**: SystemCapability.DistributedDataManager.Preferences.Core
**Parameters** **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| key | string | Yes| Key of the KV pair to delete. It cannot be empty.| | key | string | Yes| Key of the KV pair to delete. It cannot be empty.|
**Return value** **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| Promise<void> | Promise used to return the result.| | Promise<void> | Promise used to return the result.|
**Example** **Example**
```ts ```ts
...@@ -497,9 +498,9 @@ Saves the modification to this **Preferences** instance and synchronizes the mod ...@@ -497,9 +498,9 @@ Saves the modification to this **Preferences** instance and synchronizes the mod
**System capability**: SystemCapability.DistributedDataManager.Preferences.Core **System capability**: SystemCapability.DistributedDataManager.Preferences.Core
**Parameters** **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| callback | AsyncCallback<void> | Yes| Callback used to return the result.| | callback | AsyncCallback<void> | Yes| Callback used to return the result.|
**Example** **Example**
```ts ```ts
...@@ -522,9 +523,9 @@ Saves the modification to this **Preferences** instance and synchronizes the mod ...@@ -522,9 +523,9 @@ Saves the modification to this **Preferences** instance and synchronizes the mod
**System capability**: SystemCapability.DistributedDataManager.Preferences.Core **System capability**: SystemCapability.DistributedDataManager.Preferences.Core
**Return value** **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| Promise<void> | Promise used to return the result.| | Promise<void> | Promise used to return the result.|
**Example** **Example**
```ts ```ts
...@@ -545,10 +546,10 @@ Clears data of this **Preferences** instance. This API uses an asynchronous call ...@@ -545,10 +546,10 @@ Clears data of this **Preferences** instance. This API uses an asynchronous call
**System capability**: SystemCapability.DistributedDataManager.Preferences.Core **System capability**: SystemCapability.DistributedDataManager.Preferences.Core
Parameters **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| callback | AsyncCallback<void> | Yes| Callback used to return the result.| | callback | AsyncCallback<void> | Yes| Callback used to return the result.|
**Example** **Example**
```ts ```ts
...@@ -571,9 +572,9 @@ Clears data of this **Preferences** instance. This API uses a promise to return ...@@ -571,9 +572,9 @@ Clears data of this **Preferences** instance. This API uses a promise to return
**System capability**: SystemCapability.DistributedDataManager.Preferences.Core **System capability**: SystemCapability.DistributedDataManager.Preferences.Core
**Return value** **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| Promise<void> | Promise used to return the result.| | Promise<void> | Promise used to return the result.|
**Example** **Example**
```ts ```ts
...@@ -595,10 +596,10 @@ Subscribes to data changes. When the value of the subscribed key changes, a call ...@@ -595,10 +596,10 @@ Subscribes to data changes. When the value of the subscribed key changes, a call
**System capability**: SystemCapability.DistributedDataManager.Preferences.Core **System capability**: SystemCapability.DistributedDataManager.Preferences.Core
**Parameters** **Parameters**
| Name| Type|Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- |-------- | | -------- | -------- | -------- | -------- |
| type | string | Yes| Event type. The value **change** indicates data change events.| | type | string | Yes| Event type. The value **change** indicates data change events.|
| callback | Callback<{ key : string }> | Yes| Callback used to return data changes.| | callback | Callback<{ key : string }> | Yes| Callback used to return data changes.|
**Example** **Example**
```ts ```ts
...@@ -636,10 +637,10 @@ Unsubscribes from data changes. ...@@ -636,10 +637,10 @@ Unsubscribes from data changes.
**System capability**: SystemCapability.DistributedDataManager.Preferences.Core **System capability**: SystemCapability.DistributedDataManager.Preferences.Core
**Parameters** **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- |-------- | | -------- | -------- | -------- | -------- |
| type | string| Yes| Event type. The value **change** indicates data change events.| | type | string | Yes| Event type. The value **change** indicates data change events.|
| callback | Callback<{ key : string }> | No| Callback used to return data changes. If this parameter is left empty, all callbacks for data changes will be canceled.| | callback | Callback<{ key : string }> | No| Callback used to return data changes. If this parameter is left empty, all callbacks for data changes will be canceled.|
**Example** **Example**
```ts ```ts
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册