Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Docs
提交
a8add1ca
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看板
未验证
提交
a8add1ca
编写于
9月 16, 2022
作者:
O
openharmony_ci
提交者:
Gitee
9月 16, 2022
浏览文件
操作
浏览文件
下载
差异文件
!9595 【轻量级 PR】:update zh-cn/application-dev/reference/apis/js-apis-data-preferences.md.
Merge pull request !9595 from 葛亚芳/N/A
上级
0cc430e2
7eb81487
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
45 addition
and
45 deletion
+45
-45
zh-cn/application-dev/reference/apis/js-apis-data-preferences.md
...pplication-dev/reference/apis/js-apis-data-preferences.md
+45
-45
未找到文件。
zh-cn/application-dev/reference/apis/js-apis-data-preferences.md
浏览文件 @
a8add1ca
...
...
@@ -48,10 +48,10 @@ FA模型示例:
```
js
// 获取context
import
featureAbility
from
'
@ohos.ability.featureAbility
'
var
context
=
featureAbility
.
getContext
()
import
featureAbility
from
'
@ohos.ability.featureAbility
'
;
let
context
=
featureAbility
.
getContext
();
var
preferences
=
null
;
let
preferences
=
null
;
data_preferences
.
getPreferences
(
context
,
'
mystore
'
,
function
(
err
,
object
)
{
if
(
err
)
{
console
.
info
(
"
Failed to get preferences. Cause:
"
+
err
);
...
...
@@ -66,15 +66,15 @@ Stage模型示例:
```
ts
// 获取context
import
Ability
from
'
@ohos.application.Ability
'
var
context
;
import
Ability
from
'
@ohos.application.Ability
'
;
let
context
=
null
;
class
MainAbility
extends
Ability
{
onWindowStageCreate
(
windowStage
){
context
=
this
.
context
context
=
this
.
context
;
}
}
var
preferences
=
null
;
let
preferences
=
null
;
data_preferences
.
getPreferences
(
context
,
'
mystore
'
,
function
(
err
,
object
)
{
if
(
err
)
{
console
.
info
(
"
Failed to get preferences. Cause:
"
+
err
);
...
...
@@ -112,11 +112,11 @@ FA模型示例:
```
js
// 获取context
import
featureAbility
from
'
@ohos.ability.featureAbility
'
var
context
=
featureAbility
.
getContext
()
import
featureAbility
from
'
@ohos.ability.featureAbility
'
;
let
context
=
featureAbility
.
getContext
();
var
preferences
=
null
;
let
promise
=
data_preferences
.
getPreferences
(
context
,
'
mystore
'
)
let
preferences
=
null
;
let
promise
=
data_preferences
.
getPreferences
(
context
,
'
mystore
'
)
;
promise
.
then
((
object
)
=>
{
preferences
=
object
;
console
.
info
(
"
Succeeded in getting preferences.
"
);
...
...
@@ -129,16 +129,16 @@ Stage模型示例:
```
ts
// 获取context
import
Ability
from
'
@ohos.application.Ability
'
var
context
;
import
Ability
from
'
@ohos.application.Ability
'
;
let
context
=
null
;
class
MainAbility
extends
Ability
{
onWindowStageCreate
(
windowStage
){
context
=
this
.
context
context
=
this
.
context
;
}
}
var
preferences
=
null
;
let
promise
=
data_preferences
.
getPreferences
(
context
,
'
mystore
'
)
let
preferences
=
null
;
let
promise
=
data_preferences
.
getPreferences
(
context
,
'
mystore
'
)
;
promise
.
then
((
object
)
=>
{
preferences
=
object
;
console
.
info
(
"
Succeeded in getting preferences.
"
);
...
...
@@ -173,13 +173,13 @@ FA模型示例:
```
js
// 获取context
import
featureAbility
from
'
@ohos.ability.featureAbility
'
var
context
=
featureAbility
.
getContext
()
import
featureAbility
from
'
@ohos.ability.featureAbility
'
;
let
context
=
featureAbility
.
getContext
();
data_preferences
.
deletePreferences
(
context
,
'
mystore
'
,
function
(
err
)
{
if
(
err
)
{
console
.
info
(
"
Failed to delete preferences. Cause:
"
+
err
);
return
return
;
}
console
.
info
(
"
Succeeded in deleting preferences.
"
);
})
...
...
@@ -189,18 +189,18 @@ Stage模型示例:
```
ts
// 获取context
import
Ability
from
'
@ohos.application.Ability
'
var
context
import
Ability
from
'
@ohos.application.Ability
'
;
let
context
=
null
;
class
MainAbility
extends
Ability
{
onWindowStageCreate
(
windowStage
){
context
=
this
.
context
context
=
this
.
context
;
}
}
data_preferences
.
deletePreferences
(
context
,
'
mystore
'
,
function
(
err
)
{
if
(
err
)
{
console
.
info
(
"
Failed to delete preferences. Cause:
"
+
err
);
return
return
;
}
console
.
info
(
"
Succeeded in deleting preferences.
"
);
})
...
...
@@ -237,10 +237,10 @@ FA模型示例:
```
js
// 获取context
import
featureAbility
from
'
@ohos.ability.featureAbility
'
var
context
=
featureAbility
.
getContext
()
import
featureAbility
from
'
@ohos.ability.featureAbility
'
;
let
context
=
featureAbility
.
getContext
();
let
promise
=
data_preferences
.
deletePreferences
(
context
,
'
mystore
'
)
let
promise
=
data_preferences
.
deletePreferences
(
context
,
'
mystore
'
)
;
promise
.
then
(()
=>
{
console
.
info
(
"
Succeeded in deleting preferences.
"
);
}).
catch
((
err
)
=>
{
...
...
@@ -252,15 +252,15 @@ Stage模型示例:
```
ts
// 获取context
import
Ability
from
'
@ohos.application.Ability
'
var
context
import
Ability
from
'
@ohos.application.Ability
'
;
let
context
=
null
;
class
MainAbility
extends
Ability
{
onWindowStageCreate
(
windowStage
){
context
=
this
.
context
context
=
this
.
context
;
}
}
let
promise
=
data_preferences
.
deletePreferences
(
context
,
'
mystore
'
)
let
promise
=
data_preferences
.
deletePreferences
(
context
,
'
mystore
'
)
;
promise
.
then
(()
=>
{
console
.
info
(
"
Succeeded in deleting preferences.
"
);
}).
catch
((
err
)
=>
{
...
...
@@ -292,8 +292,8 @@ FA模型示例:
```
js
// 获取context
import
featureAbility
from
'
@ohos.ability.featureAbility
'
var
context
=
featureAbility
.
getContext
()
import
featureAbility
from
'
@ohos.ability.featureAbility
'
;
let
context
=
featureAbility
.
getContext
();
data_preferences
.
removePreferencesFromCache
(
context
,
'
mystore
'
,
function
(
err
)
{
if
(
err
)
{
...
...
@@ -308,11 +308,11 @@ Stage模型示例:
```
ts
// 获取context
import
Ability
from
'
@ohos.application.Ability
'
var
context
import
Ability
from
'
@ohos.application.Ability
'
;
let
context
=
null
;
class
MainAbility
extends
Ability
{
onWindowStageCreate
(
windowStage
){
context
=
this
.
context
context
=
this
.
context
;
}
}
...
...
@@ -354,10 +354,10 @@ FA模型示例:
```
js
// 获取context
import
featureAbility
from
'
@ohos.ability.featureAbility
'
var
context
=
featureAbility
.
getContext
()
import
featureAbility
from
'
@ohos.ability.featureAbility
'
;
let
context
=
featureAbility
.
getContext
();
let
promise
=
data_preferences
.
removePreferencesFromCache
(
context
,
'
mystore
'
)
let
promise
=
data_preferences
.
removePreferencesFromCache
(
context
,
'
mystore
'
)
;
promise
.
then
(()
=>
{
console
.
info
(
"
Succeeded in removing preferences.
"
);
}).
catch
((
err
)
=>
{
...
...
@@ -369,15 +369,15 @@ Stage模型示例:
```
ts
// 获取context
import
Ability
from
'
@ohos.application.Ability
'
var
context
import
Ability
from
'
@ohos.application.Ability
'
;
let
context
=
null
;
class
MainAbility
extends
Ability
{
onWindowStageCreate
(
windowStage
){
context
=
this
.
context
context
=
this
.
context
;
}
}
let
promise
=
data_preferences
.
removePreferencesFromCache
(
context
,
'
mystore
'
)
let
promise
=
data_preferences
.
removePreferencesFromCache
(
context
,
'
mystore
'
)
;
promise
.
then
(()
=>
{
console
.
info
(
"
Succeeded in removing preferences.
"
);
}).
catch
((
err
)
=>
{
...
...
@@ -828,11 +828,11 @@ data_preferences.getPreferences(this.context, 'mystore', function (err, preferen
console
.
info
(
"
Failed to get preferences.
"
);
return
;
}
var
observer
=
function
(
key
)
{
let
observer
=
function
(
key
)
{
console
.
info
(
"
The key
"
+
key
+
"
changed.
"
);
}
preferences
.
on
(
'
change
'
,
observer
);
preferences
.
put
(
'
startup
'
,
'
auto
'
,
function
(
err
)
{
preferences
.
put
(
'
startup
'
,
'
manual
'
,
function
(
err
)
{
if
(
err
)
{
console
.
info
(
"
Failed to put the value of 'startup'. Cause:
"
+
err
);
return
;
...
...
@@ -874,7 +874,7 @@ data_preferences.getPreferences(this.context, 'mystore', function (err, preferen
console
.
info
(
"
Failed to get preferences.
"
);
return
;
}
var
observer
=
function
(
key
)
{
let
observer
=
function
(
key
)
{
console
.
info
(
"
The key
"
+
key
+
"
changed.
"
);
}
preferences
.
on
(
'
change
'
,
observer
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录