未验证 提交 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. ...@@ -90,9 +90,9 @@ Use the following APIs to delete a **Storage** instance or data file.
context.getFilesDir().then((filePath) => { context.getFilesDir().then((filePath) => {
path = filePath; path = filePath;
console.info("======================>getFilesDirPromsie====================>"); 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. ...@@ -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. Use the **get\(\)** method of the **Storage** class to read data.
```js ```js
promise.then((storage) => { promise.then((storage) => {
let getPromise = storage.get('startup', 'default'); let getPromise = storage.get('startup', 'default')
getPromise.then((value) => { getPromise.then((value) => {
console.info("The value of startup is " + value); console.info("The value of startup is " + value);
}).catch((err) => { }).catch((err) => {
console.info("Failed to get the value of startup with err: " + err); console.info("Failed to get the value of startup with err: " + err);
}) })
}).catch((err) => { }).catch((err) => {
console.info("Failed to get the storage."); console.info("Failed to get the storage.")
})
``` })
```
5. Store data persistently. 5. Store data persistently.
...@@ -144,32 +145,32 @@ Use the following APIs to delete a **Storage** instance or data file. ...@@ -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. 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 ```js
promise.then((storage) => { promise.then((storage) => {
var observer = function (key) { var observer = function (key) {
console.info("The key of " + key + " changed."); console.info("The key of " + key + " changed.");
} }
storage.on('change', observer); storage.on('change', observer)
storage.putSync('startup', 'auto'); // Modify data in the Storage instance. storage.putSync('startup', 'auto'); // Modify data in the Storage instance.
storage.flushSync(); // Trigger the StorageObserver callback. storage.flushSync(); // Trigger the StorageObserver callback.
storage.off('change', observer); // Unsubscribe from the data changes. storage.off('change', observer); // Unsubscribe from the data changes.
}).catch((err) => { }).catch((err) => {
console.info("Failed to get the storage."); console.info("Failed to get the storage.");
}) })
``` ```
7. Delete the specified file. 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. 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 ```js
let promise = dataStorage.deleteStorage(path + '/mystore'); let promise = dataStorage.deleteStorage(path + '/mystore');
promise.then(() => { promise.then(() => {
console.info("Succeeded in deleting the storage."); console.info("Succeeded in deleting the storage.");
}).catch((err) => { }).catch((err) => {
console.info("Failed to deleted the storage with err: " + err); console.info("Failed to delete the storage with err: " + err);
})
``` })
```
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册