提交 11b311b4 编写于 作者: A Annie_wang

update docs

Signed-off-by: NAnnie_wang <annie.wangli@huawei.com>
上级 77002625
# Distributed Data Object
Provides basic data object management, including creating, querying, deleting, modifying, and subscribing to data objects, and distributed data object collaboration for the same application among multiple devices.
> **NOTE**<br/>
>
> The initial APIs of this module are supported since API version 8. Newly added APIs will be marked with a superscript to indicate their earliest API version.
......@@ -38,7 +41,7 @@ Creates a distributed data object.
```
## distributedObject.genSessionId()
## distributedObject.genSessionId
genSessionId(): string
......@@ -110,19 +113,19 @@ Subscribes to the changes of this distributed data object.
| callback | Callback<{ sessionId: string, fields: Array&lt;string&gt; }> | Yes| Callback used to return the changes of the distributed data object.<br>**sessionId** indicates the session ID of the distributed data object.<br>**fields** indicates the changed attributes of the distributed data object.|
**Example**
```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')
......@@ -140,20 +143,14 @@ Unsubscribes from the changes of this distributed data object.
**Example**
```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);
});
// Unregister the specified data change callback for the distributed data object.
g_object.off("change", function (sessionId, changeData) {
console.info("change" + sessionId);
});
// Unregister all data change callbacks for the distributed data object.
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"}});
// Unregister the specified data change callback.
g_object.off("change", globalThis.changeCallback);
// Unregister all data change callbacks.
g_object.off("change");
```
### on('status')
......@@ -170,14 +167,14 @@ Subscribes to the status change (online or offline) of this distributed data obj
| callback | Callback<{ sessionId: string, networkId: string, status: 'online' \| 'offline' }> | Yes| Callback used to return the status change.<br>**sessionId** indicates the session ID of the distributed data object.<br>**networkId** indicates the network ID of the device.<br>**status** indicates the status, which can be online or offline.|
**Example**
```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')
......@@ -196,15 +193,14 @@ Unsubscribes from the status change (online or offline) of this distributed data
**Example**
```js
import distributedObject from '@ohos.data.distributedDataObject';
g_object.on("status", function (sessionId, networkId, status) {
this.response += "status changed " + sessionId + " " + status + " " + networkId;
});
// Unsubscribe from the specified status change callback for the distributed data object.
g_object.off("status", function (sessionId, networkId, status) {
this.response += "status changed " + sessionId + " " + status + " " + networkId;
});
// Unsubscribe from all status change callbacks for the distributed data object.
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;
}
// Unsubscribe from the specified status change callback for the distributed data object.
g_object.off("status",globalThis.statusCallback);
// Unsubscribe from all status change callbacks for the distributed data object.
g_object.off("status");
```
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册