提交 e7c4fb92 编写于 作者: A Annie_wang

update docs

Signed-off-by: NAnnie_wang <annie.wangli@huawei.com>
上级 c2569dcb
......@@ -28,26 +28,29 @@ Obtain a **Preferences** instance for data operations. A **Preferences** instanc
| --------------------- | ------------------------------------------------------------ | ------------------------------------------------------------ |
| ohos.data.preferences | getPreferences(context: Context, name: string): Promise\<Preferences> | Obtains a **Preferences** instance.|
### Accessing Data
### Processing Data
Call the **put()** method to add or modify data in a **Preferences** instance.
Call **put()** to add or modify data in a **Preferences** instance.
Call the **get()** method to read data from a **Preferences** instance.
Call **get()** to read data from a **Preferences** instance.
Call **getAll()** to obtain an **Object** instance that contains all KV pairs in a **Preferences** instance.
**Table 2** APIs for accessing **Preferences** data
Call **delete()** to delete the KV pair of the specified key from the **Preferences** instance.
**Table 2** APIs for processing **Preferences** data
| Class | API | Description |
| ----------- | ---------------------------------------------------------- | ------------------------------------------------------------ |
| Preferences | put(key: string, value: ValueType): Promise\<void> | Writes data to the **Preferences** instance. The value to write can be a number, a string, a Boolean value, or an array of numbers, strings, or Boolean values.|
| Preferences | get(key: string, defValue: ValueType): Promise\<ValueType> | Obtains data from the **Preferences** instance. The value to read can be a number, a string, a Boolean value, or an array of numbers, strings, or Boolean values.|
| Preferences | getAll(): Promise<Object> | Obtains an **Object** instance that contains all KV pairs in the **Preferences** instance. |
| Preferences | getAll(): Promise\<Object> | Obtains an **Object** instance that contains all KV pairs in the **Preferences** instance. |
| Preferences | delete(key: string): Promise\<void> | Deletes the KV pair of the specified key from the **Preferences** instance. |
### Storing Data Persistently
Call the **flush()** method to write the cached data back to its text file for persistent storage.
Call **flush()** to write the cached data back to its text file for persistent storage.
**Table 4** API for data persistence
......@@ -68,7 +71,7 @@ You can subscribe to data changes. When the value of the subscribed key is chang
### Deleting Data
Use the following APIs to delete a **Preferences** instance or data file.
You can use the following APIs to delete a **Preferences** instance or data file.
**Table 6** APIs for deleting **Preferences**
......@@ -130,7 +133,7 @@ Use the following APIs to delete a **Preferences** instance or data file.
3. Write data.
Use the **preferences.put()** method to write data to the **Preferences** instance.
Use **preferences.put()** to write data to the **Preferences** instance.
```js
let putPromise = preferences.put('startup', 'auto');
......@@ -143,7 +146,7 @@ Use the following APIs to delete a **Preferences** instance or data file.
4. Read data.
Use the **preferences.get()** method to read data.
Use **preferences.get()** to read data.
```js
let getPromise = preferences.get('startup', 'default');
......@@ -156,7 +159,7 @@ Use the following APIs to delete a **Preferences** instance or data file.
5. Store data persistently.
Use the **flush()** method to flush data from the **Preferences** instance to its file.
Use **flush()** to flush data from the **Preferences** instance to its file.
```js
preferences.flush();
......@@ -190,7 +193,7 @@ Use the following APIs to delete a **Preferences** instance or data file.
7. Delete the specified file.
Use the **deletePreferences** method to delete the **Preferences** instance and its persistent file and backup and corrupted files. After the specified files are deleted, the application cannot use that instance to perform any data operation. Otherwise, data inconsistency will be caused. The deleted data and files cannot be restored.
Use **deletePreferences()** to delete the **Preferences** instance and its persistent file and backup and corrupted files. After the specified files are deleted, the application cannot use that instance to perform any data operation. Otherwise, data inconsistency will be caused. The deleted data and files cannot be restored.
```js
let proDelete = data_preferences.deletePreferences(context, 'mystore');
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册