Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Docs
提交
3014ccf0
D
Docs
项目概览
OpenHarmony
/
Docs
1 年多 前同步成功
通知
159
Star
292
Fork
28
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
D
Docs
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
3014ccf0
编写于
8月 30, 2022
作者:
O
openharmony_ci
提交者:
Gitee
8月 30, 2022
浏览文件
操作
浏览文件
下载
差异文件
!8876 3.2Beta2:data-storage示例代码修改,需同步翻译
Merge pull request !8876 from 葛亚芳/OpenHarmony-3.2-Beta2
上级
9b958fff
aa2a48ac
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
52 addition
and
55 deletion
+52
-55
zh-cn/application-dev/reference/apis/js-apis-data-storage.md
zh-cn/application-dev/reference/apis/js-apis-data-storage.md
+52
-55
未找到文件。
zh-cn/application-dev/reference/apis/js-apis-data-storage.md
浏览文件 @
3014ccf0
...
...
@@ -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
<
void
>
): 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.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录