Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Docs
提交
afcf7da4
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看板
未验证
提交
afcf7da4
编写于
6月 17, 2022
作者:
O
openharmony_ci
提交者:
Gitee
6月 17, 2022
浏览文件
操作
浏览文件
下载
差异文件
!5525 【轻量级 PR】:master:update js-apis-data-distributedobject.md:自动化测试问题修改+添加模块功能简介+补充接口版本标记
Merge pull request !5525 from 葛亚芳/N/A
上级
211eafcb
ea563f0d
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
54 addition
and
54 deletion
+54
-54
zh-cn/application-dev/reference/apis/js-apis-data-distributedobject.md
...tion-dev/reference/apis/js-apis-data-distributedobject.md
+54
-54
未找到文件。
zh-cn/application-dev/reference/apis/js-apis-data-distributedobject.md
浏览文件 @
afcf7da4
# 分布式数据对象
本模块提供管理基本数据对象的相关能力,包括创建、查询、删除、修改、订阅等;同时支持相同应用多设备间的分布式数据对象协同能力。
> **说明:**
>
> 本模块首批接口从API version 8开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
...
...
@@ -38,7 +41,7 @@ createDistributedObject(source: object): DistributedObject
```
## distributedObject.genSessionId
()
## distributedObject.genSessionId
genSessionId(): string
...
...
@@ -57,7 +60,7 @@ genSessionId(): string
var
sessionId
=
distributedObject
.
genSessionId
();
```
## SaveSuccessResponse
## SaveSuccessResponse
<sup>9+</sup>
save接口回调信息。
...
...
@@ -69,7 +72,7 @@ save接口回调信息。
| version | number |已保存对象的版本。 |
| deviceId | string | 存储数据的设备号,标识需要保存对象的设备。默认为"local",标识本地设备;可自定义设置其他标识设备的字符串。 |
## RevokeSaveSuccessResponse
## RevokeSaveSuccessResponse
<sup>9+</sup>
revokeSave接口回调信息。
...
...
@@ -133,19 +136,19 @@ on(type: 'change', callback: Callback<{ sessionId: string, fields: Array<stri
| callback | Callback
<
{
sessionId:
string
,
fields:
Array
&
lt
;
string
&
gt
;
}
>
| 是 | 变更回调对象实例。
<br>
sessionId:标识变更对象的sessionId;
<br>
fields:标识对象变更的属性名。 |
**示例:**
```
js
import
distributedObject
from
'
@ohos.data.distributedDataObject
'
;
var
g_object
=
distributedObject
.
createDistributedObject
({
name
:
"
Amy
"
,
age
:
18
,
isVis
:
false
,
parent
:{
mother
:
"
jack mom
"
,
father
:
"
jack Dad
"
}});
g_object
.
on
(
"
change
"
,
function
(
sessionId
,
changeData
)
{
console
.
info
(
"
change
"
+
sessionId
);
if
(
changeData
!=
null
&&
changeData
!=
undefined
)
{
changeData
.
forEach
(
element
=>
{
console
.
info
(
"
changed !
"
+
element
+
"
"
+
g_object
[
element
]
);
});
}
}
);
```
```
js
import
distributedObject
from
'
@ohos.data.distributedDataObject
'
;
var
g_object
=
distributedObject
.
createDistributedObject
({
name
:
"
Amy
"
,
age
:
18
,
isVis
:
false
,
parent
:{
mother
:
"
jack mom
"
,
father
:
"
jack Dad
"
}});
globalThis
.
changeCallback
=
(
sessionId
,
changeData
)
=>
{
console
.
info
(
"
change
"
+
sessionId
);
if
(
changeData
!=
null
&&
changeData
!=
undefined
)
{
changeData
.
forEach
(
element
=>
{
console
.
info
(
"
changed !
"
+
element
+
"
"
+
g_object
[
element
]);
}
);
}
}
g_object
.
on
(
"
change
"
,
globalThis
.
changeCallback
);
```
### off('change')
...
...
@@ -163,17 +166,14 @@ off(type: 'change', callback?: Callback<{ sessionId: string, fields: Array<st
**示例:**
```
js
import
distributedObject
from
'
@ohos.data.distributedDataObject
'
;
var
g_object
=
distributedObject
.
createDistributedObject
({
name
:
"
Amy
"
,
age
:
18
,
isVis
:
false
,
parent
:{
mother
:
"
jack mom
"
,
father
:
"
jack Dad
"
}});
//删除数据变更回调changeCallback
g_object
.
off
(
"
change
"
,
function
(
sessionId
,
changeData
)
{
console
.
info
(
"
change
"
+
sessionId
);
});
//删除所有的数据变更回调
g_object
.
off
(
"
change
"
);
```
```
js
import
distributedObject
from
'
@ohos.data.distributedDataObject
'
;
var
g_object
=
distributedObject
.
createDistributedObject
({
name
:
"
Amy
"
,
age
:
18
,
isVis
:
false
,
parent
:{
mother
:
"
jack mom
"
,
father
:
"
jack Dad
"
}});
//删除数据变更回调changeCallback
g_object
.
off
(
"
change
"
,
globalThis
.
changeCallback
);
//删除所有的数据变更回调
g_object
.
off
(
"
change
"
);
```
### on('status')
...
...
@@ -190,14 +190,14 @@ on(type: 'status', callback: Callback<{ sessionId: string, networkId: string, st
| callback | Callback
<
{
sessionId:
string
,
networkId:
string
,
status:
'
online
'
\|
'
offline
'
}
>
| 是 | 监听上下线回调实例。
<br>
sessionId:标识变更对象的sessionId;
<br>
networkId:标识对象设备,即deviceId;
<br>
status:标识对象为'online'(上线)或'offline'(下线)的状态。 |
**示例:**
```
js
import
distributedObject
from
'
@ohos.data.distributedDataObject
'
;
var
g_object
=
distributedObject
.
createDistributedObject
({
name
:
"
Amy
"
,
age
:
18
,
isVis
:
false
,
parent
:{
mother
:
"
jack mom
"
,
father
:
"
jack Dad
"
}})
;
g_object
.
on
(
"
status
"
,
function
(
sessionId
,
networkId
,
status
)
{
this
.
response
+=
"
status changed
"
+
sessionId
+
"
"
+
status
+
"
"
+
networkId
;
}
);
```
```
js
import
distributedObject
from
'
@ohos.data.distributedDataObject
'
;
globalThis
.
statusCallback
=
(
sessionId
,
networkId
,
status
)
=>
{
globalThis
.
response
+=
"
status changed
"
+
sessionId
+
"
"
+
status
+
"
"
+
networkId
;
}
var
g_object
=
distributedObject
.
createDistributedObject
({
name
:
"
Amy
"
,
age
:
18
,
isVis
:
false
,
parent
:{
mother
:
"
jack mom
"
,
father
:
"
jack Dad
"
}})
;
g_object
.
on
(
"
status
"
,
globalThis
.
statusCallback
);
```
### off('status')
...
...
@@ -216,17 +216,19 @@ off(type: 'status', callback?: Callback<{ sessionId: string, deviceId: string, s
**示例:**
```
js
import
distributedObject
from
'
@ohos.data.distributedDataObject
'
;
//删除上下线回调changeCallback
g_object
.
off
(
"
status
"
,
function
(
sessionId
,
networkId
,
status
)
{
this
.
response
+=
"
status changed
"
+
sessionId
+
"
"
+
status
+
"
"
+
networkId
;
});
//删除所有的上下线回调
g_object
.
off
(
"
status
"
);
```
```
js
import
distributedObject
from
'
@ohos.data.distributedDataObject
'
;
var
g_object
=
distributedObject
.
createDistributedObject
({
name
:
"
Amy
"
,
age
:
18
,
isVis
:
false
,
parent
:{
mother
:
"
jack mom
"
,
father
:
"
jack Dad
"
}});
globalThis
.
statusCallback
=
(
sessionId
,
networkId
,
status
)
=>
{
globalThis
.
response
+=
"
status changed
"
+
sessionId
+
"
"
+
status
+
"
"
+
networkId
;
}
//删除上下线回调changeCallback
g_object
.
off
(
"
status
"
,
globalThis
.
statusCallback
);
//删除所有的上下线回调
g_object
.
off
(
"
status
"
);
```
### save
### save
<sup>9+</sup>
save(deviceId: string, callback: AsyncCallback
<
SaveSuccessResponse
>
): void
...
...
@@ -250,7 +252,7 @@ save(deviceId: string, callback: AsyncCallback<SaveSuccessResponse>): void
**示例:**
```
j
s
```
t
s
import
distributedObject
from
'
@ohos.data.distributedDataObject
'
;
var
g_object
=
distributedObject
.
createDistributedObject
({
name
:
"
Amy
"
,
age
:
18
,
isVis
:
false
});
g_object
.
setSessionId
(
"
123456
"
);
...
...
@@ -260,10 +262,9 @@ save(deviceId: string, callback: AsyncCallback<SaveSuccessResponse>): void
console
.
info
(
"
save version
"
+
result
.
version
);
console
.
info
(
"
save deviceId
"
+
result
.
deviceId
);
});
```
### save
### save
<sup>9+</sup>
save(deviceId: string): Promise
<
SaveSuccessResponse
>
...
...
@@ -292,7 +293,7 @@ save(deviceId: string): Promise<SaveSuccessResponse>
**示例:**
```
j
s
```
t
s
import
distributedObject
from
'
@ohos.data.distributedDataObject
'
;
var
g_object
=
distributedObject
.
createDistributedObject
({
name
:
"
Amy
"
,
age
:
18
,
isVis
:
false
});
g_object
.
setSessionId
(
"
123456
"
);
...
...
@@ -304,10 +305,9 @@ save(deviceId: string): Promise<SaveSuccessResponse>
},
()
=>
{
console
.
error
(
"
save failed
"
);
});
```
### revokeSave
### revokeSave
<sup>9+</sup>
revokeSave(callback: AsyncCallback
<
SaveSuccessResponse
>
): void
...
...
@@ -325,7 +325,7 @@ revokeSave(callback: AsyncCallback<SaveSuccessResponse>): void
**示例:**
```
j
s
```
t
s
import
distributedObject
from
'
@ohos.data.distributedDataObject
'
;
var
g_object
=
distributedObject
.
createDistributedObject
({
name
:
"
Amy
"
,
age
:
18
,
isVis
:
false
});
g_object
.
setSessionId
(
"
123456
"
);
...
...
@@ -334,7 +334,7 @@ revokeSave(callback: AsyncCallback<SaveSuccessResponse>): void
});
```
### revokeSave
### revokeSave
<sup>9+</sup>
revokeSave(): Promise
<
SaveSuccessResponse
>
...
...
@@ -353,7 +353,7 @@ revokeSave(): Promise<SaveSuccessResponse>
**示例:**
```
j
s
```
t
s
import
distributedObject
from
'
@ohos.data.distributedDataObject
'
;
var
g_object
=
distributedObject
.
createDistributedObject
({
name
:
"
Amy
"
,
age
:
18
,
isVis
:
false
});
g_object
.
setSessionId
(
"
123456
"
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录