Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Docs
提交
3167c5dc
D
Docs
项目概览
OpenHarmony
/
Docs
大约 2 年 前同步成功
通知
161
Star
293
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看板
未验证
提交
3167c5dc
编写于
9月 14, 2022
作者:
葛
葛亚芳
提交者:
Gitee
9月 14, 2022
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
preferences API补充FA模型与Stage模型的不同context获取使用方式
Signed-off-by:
N
葛亚芳
<
geyafang@huawei.com
>
上级
e3fabd87
变更
1
显示空白变更内容
内联
并排
Showing
1 changed file
with
163 addition
and
6 deletion
+163
-6
zh-cn/application-dev/reference/apis/js-apis-data-preferences.md
...pplication-dev/reference/apis/js-apis-data-preferences.md
+163
-6
未找到文件。
zh-cn/application-dev/reference/apis/js-apis-data-preferences.md
浏览文件 @
3167c5dc
...
@@ -44,9 +44,15 @@ getPreferences(context: Context, name: string, callback: AsyncCallback<Prefer
...
@@ -44,9 +44,15 @@ getPreferences(context: Context, name: string, callback: AsyncCallback<Prefer
**示例:**
**示例:**
FA模型示例:
```
js
```
js
// 获取context
import
featureAbility
from
'
@ohos.ability.featureAbility
'
var
context
=
featureAbility
.
getContext
()
var
preferences
=
null
;
var
preferences
=
null
;
data_preferences
.
getPreferences
(
this
.
context
,
'
mystore
'
,
function
(
err
,
object
)
{
data_preferences
.
getPreferences
(
context
,
'
mystore
'
,
function
(
err
,
object
)
{
if
(
err
)
{
if
(
err
)
{
console
.
info
(
"
Failed to get preferences. Cause:
"
+
err
);
console
.
info
(
"
Failed to get preferences. Cause:
"
+
err
);
return
;
return
;
...
@@ -56,6 +62,28 @@ data_preferences.getPreferences(this.context, 'mystore', function (err, object)
...
@@ -56,6 +62,28 @@ data_preferences.getPreferences(this.context, 'mystore', function (err, object)
})
})
```
```
Stage模型示例:
```
ts
// 获取context
import
Ability
from
'
@ohos.application.Ability
'
var
context
;
class
MainAbility
extends
Ability
{
onWindowStageCreate
(
windowStage
){
context
=
this
.
context
}
}
var
preferences
=
null
;
data_preferences
.
getPreferences
(
context
,
'
mystore
'
,
function
(
err
,
object
)
{
if
(
err
)
{
console
.
info
(
"
Failed to get preferences. Cause:
"
+
err
);
return
;
}
preferences
=
object
;
console
.
info
(
"
Succeeded in getting preferences.
"
);
})
```
## data_preferences.getPreferences
## data_preferences.getPreferences
...
@@ -80,9 +108,15 @@ getPreferences(context: Context, name: string): Promise<Preferences>
...
@@ -80,9 +108,15 @@ getPreferences(context: Context, name: string): Promise<Preferences>
**示例:**
**示例:**
FA模型示例:
```
js
```
js
// 获取context
import
featureAbility
from
'
@ohos.ability.featureAbility
'
var
context
=
featureAbility
.
getContext
()
var
preferences
=
null
;
var
preferences
=
null
;
let
promise
=
data_preferences
.
getPreferences
(
this
.
context
,
'
mystore
'
)
let
promise
=
data_preferences
.
getPreferences
(
context
,
'
mystore
'
)
promise
.
then
((
object
)
=>
{
promise
.
then
((
object
)
=>
{
preferences
=
object
;
preferences
=
object
;
console
.
info
(
"
Succeeded in getting preferences.
"
);
console
.
info
(
"
Succeeded in getting preferences.
"
);
...
@@ -91,6 +125,27 @@ promise.then((object) => {
...
@@ -91,6 +125,27 @@ promise.then((object) => {
})
})
```
```
Stage模型示例:
```
ts
// 获取context
import
Ability
from
'
@ohos.application.Ability
'
var
context
;
class
MainAbility
extends
Ability
{
onWindowStageCreate
(
windowStage
){
context
=
this
.
context
}
}
var
preferences
=
null
;
let
promise
=
data_preferences
.
getPreferences
(
context
,
'
mystore
'
)
promise
.
then
((
object
)
=>
{
preferences
=
object
;
console
.
info
(
"
Succeeded in getting preferences.
"
);
}).
catch
((
err
)
=>
{
console
.
info
(
"
Failed to get preferences. Cause:
"
+
err
);
})
```
## data_preferences.deletePreferences
## data_preferences.deletePreferences
...
@@ -114,8 +169,14 @@ deletePreferences(context: Context, name: string, callback: AsyncCallback<voi
...
@@ -114,8 +169,14 @@ deletePreferences(context: Context, name: string, callback: AsyncCallback<voi
**示例:**
**示例:**
FA模型示例:
```
js
```
js
data_preferences
.
deletePreferences
(
this
.
context
,
'
mystore
'
,
function
(
err
)
{
// 获取context
import
featureAbility
from
'
@ohos.ability.featureAbility
'
var
context
=
featureAbility
.
getContext
()
data_preferences
.
deletePreferences
(
context
,
'
mystore
'
,
function
(
err
)
{
if
(
err
)
{
if
(
err
)
{
console
.
info
(
"
Failed to delete preferences. Cause:
"
+
err
);
console
.
info
(
"
Failed to delete preferences. Cause:
"
+
err
);
return
return
...
@@ -124,6 +185,26 @@ data_preferences.deletePreferences(this.context, 'mystore', function (err) {
...
@@ -124,6 +185,26 @@ data_preferences.deletePreferences(this.context, 'mystore', function (err) {
})
})
```
```
Stage模型示例:
```
ts
// 获取context
import
Ability
from
'
@ohos.application.Ability
'
var
context
class
MainAbility
extends
Ability
{
onWindowStageCreate
(
windowStage
){
context
=
this
.
context
}
}
data_preferences
.
deletePreferences
(
context
,
'
mystore
'
,
function
(
err
)
{
if
(
err
)
{
console
.
info
(
"
Failed to delete preferences. Cause:
"
+
err
);
return
}
console
.
info
(
"
Succeeded in deleting preferences.
"
);
})
```
## data_preferences.deletePreferences
## data_preferences.deletePreferences
...
@@ -152,8 +233,14 @@ deletePreferences(context: Context, name: string): Promise<void>
...
@@ -152,8 +233,14 @@ deletePreferences(context: Context, name: string): Promise<void>
**示例:**
**示例:**
FA模型示例:
```
js
```
js
let
promise
=
data_preferences
.
deletePreferences
(
this
.
context
,
'
mystore
'
)
// 获取context
import
featureAbility
from
'
@ohos.ability.featureAbility
'
var
context
=
featureAbility
.
getContext
()
let
promise
=
data_preferences
.
deletePreferences
(
context
,
'
mystore
'
)
promise
.
then
(()
=>
{
promise
.
then
(()
=>
{
console
.
info
(
"
Succeeded in deleting preferences.
"
);
console
.
info
(
"
Succeeded in deleting preferences.
"
);
}).
catch
((
err
)
=>
{
}).
catch
((
err
)
=>
{
...
@@ -161,6 +248,25 @@ promise.then(() => {
...
@@ -161,6 +248,25 @@ promise.then(() => {
})
})
```
```
Stage模型示例:
```
ts
// 获取context
import
Ability
from
'
@ohos.application.Ability
'
var
context
class
MainAbility
extends
Ability
{
onWindowStageCreate
(
windowStage
){
context
=
this
.
context
}
}
let
promise
=
data_preferences
.
deletePreferences
(
context
,
'
mystore
'
)
promise
.
then
(()
=>
{
console
.
info
(
"
Succeeded in deleting preferences.
"
);
}).
catch
((
err
)
=>
{
console
.
info
(
"
Failed to delete preferences. Cause:
"
+
err
);
})
```
## data_preferences.removePreferencesFromCache
## data_preferences.removePreferencesFromCache
...
@@ -182,8 +288,14 @@ removePreferencesFromCache(context: Context, name: string, callback: AsyncCallba
...
@@ -182,8 +288,14 @@ removePreferencesFromCache(context: Context, name: string, callback: AsyncCallba
**示例:**
**示例:**
FA模型示例:
```
js
```
js
data_preferences
.
removePreferencesFromCache
(
this
.
context
,
'
mystore
'
,
function
(
err
)
{
// 获取context
import
featureAbility
from
'
@ohos.ability.featureAbility
'
var
context
=
featureAbility
.
getContext
()
data_preferences
.
removePreferencesFromCache
(
context
,
'
mystore
'
,
function
(
err
)
{
if
(
err
)
{
if
(
err
)
{
console
.
info
(
"
Failed to remove preferences. Cause:
"
+
err
);
console
.
info
(
"
Failed to remove preferences. Cause:
"
+
err
);
return
;
return
;
...
@@ -192,6 +304,26 @@ data_preferences.removePreferencesFromCache(this.context, 'mystore', function (e
...
@@ -192,6 +304,26 @@ data_preferences.removePreferencesFromCache(this.context, 'mystore', function (e
})
})
```
```
Stage模型示例:
```
ts
// 获取context
import
Ability
from
'
@ohos.application.Ability
'
var
context
class
MainAbility
extends
Ability
{
onWindowStageCreate
(
windowStage
){
context
=
this
.
context
}
}
data_preferences
.
removePreferencesFromCache
(
context
,
'
mystore
'
,
function
(
err
)
{
if
(
err
)
{
console
.
info
(
"
Failed to remove preferences. Cause:
"
+
err
);
return
;
}
console
.
info
(
"
Succeeded in removing preferences.
"
);
})
```
## data_preferences.removePreferencesFromCache
## data_preferences.removePreferencesFromCache
...
@@ -218,8 +350,14 @@ removePreferencesFromCache(context: Context, name: string): Promise<void>
...
@@ -218,8 +350,14 @@ removePreferencesFromCache(context: Context, name: string): Promise<void>
**示例:**
**示例:**
FA模型示例:
```
js
```
js
let
promise
=
data_preferences
.
removePreferencesFromCache
(
this
.
context
,
'
mystore
'
)
// 获取context
import
featureAbility
from
'
@ohos.ability.featureAbility
'
var
context
=
featureAbility
.
getContext
()
let
promise
=
data_preferences
.
removePreferencesFromCache
(
context
,
'
mystore
'
)
promise
.
then
(()
=>
{
promise
.
then
(()
=>
{
console
.
info
(
"
Succeeded in removing preferences.
"
);
console
.
info
(
"
Succeeded in removing preferences.
"
);
}).
catch
((
err
)
=>
{
}).
catch
((
err
)
=>
{
...
@@ -227,6 +365,25 @@ promise.then(() => {
...
@@ -227,6 +365,25 @@ promise.then(() => {
})
})
```
```
Stage模型示例:
```
ts
// 获取context
import
Ability
from
'
@ohos.application.Ability
'
var
context
class
MainAbility
extends
Ability
{
onWindowStageCreate
(
windowStage
){
context
=
this
.
context
}
}
let
promise
=
data_preferences
.
removePreferencesFromCache
(
context
,
'
mystore
'
)
promise
.
then
(()
=>
{
console
.
info
(
"
Succeeded in removing preferences.
"
);
}).
catch
((
err
)
=>
{
console
.
info
(
"
Failed to remove preferences. Cause:
"
+
err
);
})
```
## Preferences
## Preferences
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录