未验证 提交 61d907c2 编写于 作者: O openharmony_ci 提交者: Gitee

!8877 3.1Release:data-storage示例代码修改,需同步翻译

Merge pull request !8877 from 葛亚芳/OpenHarmony-3.1-Release
...@@ -88,9 +88,9 @@ ...@@ -88,9 +88,9 @@
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');
``` ```
3. 存入数据。 3. 存入数据。
...@@ -99,7 +99,7 @@ ...@@ -99,7 +99,7 @@
```js ```js
promise.then((storage) => { promise.then((storage) => {
let getPromise = storage.put('startup', 'auto'); // 保存数据到缓存的storage示例中。 let getPromise = storage.put('startup', 'auto'); // 保存数据到缓存的storage实例中
getPromise.then(() => { getPromise.then(() => {
console.info("Succeeded in putting the value of startup."); console.info("Succeeded in putting the value of startup.");
}).catch((err) => { }).catch((err) => {
......
...@@ -52,13 +52,13 @@ import featureAbility from '@ohos.ability.featureAbility'; ...@@ -52,13 +52,13 @@ import featureAbility from '@ohos.ability.featureAbility';
var path; var path;
var context = featureAbility.getContext(); var context = featureAbility.getContext();
context.getFilesDir().then((filePath) => { context.getFilesDir().then((filePath) => {
path = filePath; path = filePath;
console.info("======================>getFilesDirPromsie====================>"); console.info("======================>getFilesDirPromsie====================>");
});
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();
});
``` ```
...@@ -85,18 +85,18 @@ import featureAbility from '@ohos.ability.featureAbility'; ...@@ -85,18 +85,18 @@ import featureAbility from '@ohos.ability.featureAbility';
var path; var path;
var context = featureAbility.getContext(); var context = featureAbility.getContext();
context.getFilesDir().then((filePath) => { context.getFilesDir().then((filePath) => {
path = filePath; path = filePath;
console.info("======================>getFilesDirPromsie====================>"); console.info("======================>getFilesDirPromsie====================>");
});
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();
}) })
});
``` ```
...@@ -128,17 +128,17 @@ import featureAbility from '@ohos.ability.featureAbility'; ...@@ -128,17 +128,17 @@ import featureAbility from '@ohos.ability.featureAbility';
var path; var path;
var context = featureAbility.getContext(); var context = featureAbility.getContext();
context.getFilesDir().then((filePath) => { context.getFilesDir().then((filePath) => {
path = filePath; path = filePath;
console.info("======================>getFilesDirPromsie====================>"); console.info("======================>getFilesDirPromsie====================>");
});
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');
}) })
});
``` ```
...@@ -166,12 +166,11 @@ var context = featureAbility.getContext(); ...@@ -166,12 +166,11 @@ var context = featureAbility.getContext();
context.getFilesDir().then((filePath) => { context.getFilesDir().then((filePath) => {
path = filePath; path = filePath;
console.info("======================>getFilesDirPromsie====================>"); console.info("======================>getFilesDirPromsie====================>");
});
data_storage.deleteStorageSync(path + '/mystore'); data_storage.deleteStorageSync(path + '/mystore');
});
``` ```
## data_storage.deleteStorage ## data_storage.deleteStorage
deleteStorage(path: string, callback: AsyncCallback<void>): void deleteStorage(path: string, callback: AsyncCallback<void>): void
...@@ -195,17 +194,17 @@ import featureAbility from '@ohos.ability.featureAbility'; ...@@ -195,17 +194,17 @@ import featureAbility from '@ohos.ability.featureAbility';
var path; var path;
var context = featureAbility.getContext(); var context = featureAbility.getContext();
context.getFilesDir().then((filePath) => { context.getFilesDir().then((filePath) => {
path = filePath; path = filePath;
console.info("======================>getFilesDirPromsie====================>"); console.info("======================>getFilesDirPromsie====================>");
});
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.");
}) })
});
``` ```
...@@ -237,16 +236,16 @@ import featureAbility from '@ohos.ability.featureAbility'; ...@@ -237,16 +236,16 @@ import featureAbility from '@ohos.ability.featureAbility';
var path; var path;
var context = featureAbility.getContext(); var context = featureAbility.getContext();
context.getFilesDir().then((filePath) => { context.getFilesDir().then((filePath) => {
path = filePath; path = filePath;
console.info("======================>getFilesDirPromsie====================>"); console.info("======================>getFilesDirPromsie====================>");
});
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);
}) })
});
``` ```
...@@ -273,9 +272,9 @@ var context = featureAbility.getContext(); ...@@ -273,9 +272,9 @@ var context = featureAbility.getContext();
context.getFilesDir().then((filePath) => { context.getFilesDir().then((filePath) => {
path = filePath; path = filePath;
console.info("======================>getFilesDirPromsie====================>"); console.info("======================>getFilesDirPromsie====================>");
data_storage.removeStorageFromCacheSync(path + '/mystore');
}); });
data_storage.removeStorageFromCacheSync(path + '/mystore');
``` ```
...@@ -302,17 +301,17 @@ import featureAbility from '@ohos.ability.featureAbility'; ...@@ -302,17 +301,17 @@ import featureAbility from '@ohos.ability.featureAbility';
var path; var path;
var context = featureAbility.getContext(); var context = featureAbility.getContext();
context.getFilesDir().then((filePath) => { context.getFilesDir().then((filePath) => {
path = filePath; path = filePath;
console.info("======================>getFilesDirPromsie====================>"); console.info("======================>getFilesDirPromsie====================>");
});
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.");
}) })
});
``` ```
...@@ -344,24 +343,22 @@ import featureAbility from '@ohos.ability.featureAbility'; ...@@ -344,24 +343,22 @@ import featureAbility from '@ohos.ability.featureAbility';
var path; var path;
var context = featureAbility.getContext(); var context = featureAbility.getContext();
context.getFilesDir().then((filePath) => { context.getFilesDir().then((filePath) => {
path = filePath; path = filePath;
console.info("======================>getFilesDirPromsie====================>"); console.info("======================>getFilesDirPromsie====================>");
});
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
提供获取和修改存储数据的接口。 提供获取和修改存储数据的接口。
### getSync ### getSync
getSync(key: string, defValue: ValueType): ValueType getSync(key: string, defValue: ValueType): ValueType
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册