未验证 提交 aa2a48ac 编写于 作者: 葛亚芳 提交者: Gitee

update zh-cn/application-dev/reference/apis/js-apis-data-storage.md.

Signed-off-by: N@ge-yafang <geyafang@huawei.com>
Signed-off-by: N葛亚芳 <geyafang@huawei.com>
上级 bb829809
......@@ -54,13 +54,13 @@ import featureAbility from '@ohos.ability.featureAbility';
var path;
var context = featureAbility.getContext();
context.getFilesDir().then((filePath) => {
path = filePath;
console.info("======================>getFilesDirPromsie====================>");
});
path = filePath;
console.info("======================>getFilesDirPromsie====================>");
let storage = data_storage.getStorageSync(path + '/mystore');
storage.putSync('startup', 'auto');
storage.flushSync();
let storage = data_storage.getStorageSync(path + '/mystore');
storage.putSync('startup', 'auto');
storage.flushSync();
});
```
......@@ -87,18 +87,18 @@ import featureAbility from '@ohos.ability.featureAbility';
var path;
var context = featureAbility.getContext();
context.getFilesDir().then((filePath) => {
path = filePath;
console.info("======================>getFilesDirPromsie====================>");
});
path = filePath;
console.info("======================>getFilesDirPromsie====================>");
data_storage.getStorage(path + '/mystore', function (err, storage) {
data_storage.getStorage(path + '/mystore', function (err, storage) {
if (err) {
console.info("Failed to get the storage. path: " + path + '/mystore');
return;
console.info("Failed to get the storage. path: " + path + '/mystore');
return;
}
storage.putSync('startup', 'auto');
storage.flushSync();
})
})
});
```
......@@ -130,17 +130,17 @@ import featureAbility from '@ohos.ability.featureAbility';
var path;
var context = featureAbility.getContext();
context.getFilesDir().then((filePath) => {
path = filePath;
console.info("======================>getFilesDirPromsie====================>");
});
path = filePath;
console.info("======================>getFilesDirPromsie====================>");
let getPromise = data_storage.getStorage(path + '/mystore');
getPromise.then((storage) => {
let getPromise = data_storage.getStorage(path + '/mystore');
getPromise.then((storage) => {
storage.putSync('startup', 'auto');
storage.flushSync();
}).catch((err) => {
}).catch((err) => {
console.info("Failed to get the storage. path: " + path + '/mystore');
})
})
});
```
......@@ -168,12 +168,11 @@ var context = featureAbility.getContext();
context.getFilesDir().then((filePath) => {
path = filePath;
console.info("======================>getFilesDirPromsie====================>");
});
data_storage.deleteStorageSync(path + '/mystore');
data_storage.deleteStorageSync(path + '/mystore');
});
```
## data_storage.deleteStorage
deleteStorage(path: string, callback: AsyncCallback&lt;void&gt;): void
......@@ -197,17 +196,17 @@ import featureAbility from '@ohos.ability.featureAbility';
var path;
var context = featureAbility.getContext();
context.getFilesDir().then((filePath) => {
path = filePath;
console.info("======================>getFilesDirPromsie====================>");
});
path = filePath;
console.info("======================>getFilesDirPromsie====================>");
data_storage.deleteStorage(path + '/mystore', function (err) {
data_storage.deleteStorage(path + '/mystore', function (err) {
if (err) {
console.info("Failed to delete the storage with err: " + err);
return;
console.info("Failed to delete the storage with err: " + err);
return;
}
console.info("Succeeded in deleting the storage.");
})
})
});
```
......@@ -239,16 +238,16 @@ import featureAbility from '@ohos.ability.featureAbility';
var path;
var context = featureAbility.getContext();
context.getFilesDir().then((filePath) => {
path = filePath;
console.info("======================>getFilesDirPromsie====================>");
});
path = filePath;
console.info("======================>getFilesDirPromsie====================>");
let promisedelSt = data_storage.deleteStorage(path + '/mystore');
promisedelSt.then(() => {
let promisedelSt = data_storage.deleteStorage(path + '/mystore');
promisedelSt.then(() => {
console.info("Succeeded in deleting the storage.");
}).catch((err) => {
}).catch((err) => {
console.info("Failed to delete the storage with err: " + err);
})
})
});
```
......@@ -275,9 +274,9 @@ var context = featureAbility.getContext();
context.getFilesDir().then((filePath) => {
path = filePath;
console.info("======================>getFilesDirPromsie====================>");
data_storage.removeStorageFromCacheSync(path + '/mystore');
});
data_storage.removeStorageFromCacheSync(path + '/mystore');
```
......@@ -304,17 +303,17 @@ import featureAbility from '@ohos.ability.featureAbility';
var path;
var context = featureAbility.getContext();
context.getFilesDir().then((filePath) => {
path = filePath;
console.info("======================>getFilesDirPromsie====================>");
});
path = filePath;
console.info("======================>getFilesDirPromsie====================>");
data_storage.removeStorageFromCache(path + '/mystore', function (err) {
data_storage.removeStorageFromCache(path + '/mystore', function (err) {
if (err) {
console.info("Failed to remove storage from cache with err: " + err);
return;
console.info("Failed to remove storage from cache with err: " + err);
return;
}
console.info("Succeeded in removing storage from cache.");
})
})
});
```
......@@ -346,24 +345,22 @@ import featureAbility from '@ohos.ability.featureAbility';
var path;
var context = featureAbility.getContext();
context.getFilesDir().then((filePath) => {
path = filePath;
console.info("======================>getFilesDirPromsie====================>");
});
path = filePath;
console.info("======================>getFilesDirPromsie====================>");
let promiserevSt = data_storage.removeStorageFromCache(path + '/mystore')
promiserevSt.then(() => {
let promiserevSt = data_storage.removeStorageFromCache(path + '/mystore')
promiserevSt.then(() => {
console.info("Succeeded in removing storage from cache.");
}).catch((err) => {
}).catch((err) => {
console.info("Failed to remove storage from cache with err: " + err);
})
})
});
```
## Storage
提供获取和修改存储数据的接口。
### getSync
getSync(key: string, defValue: ValueType): ValueType
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册