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

update docs

Signed-off-by: NAnnie_wang <annie.wangli@huawei.com>
上级 77002625
# Distributed Data Object # 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/> > **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. > 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. ...@@ -38,7 +41,7 @@ Creates a distributed data object.
``` ```
## distributedObject.genSessionId() ## distributedObject.genSessionId
genSessionId(): string genSessionId(): string
...@@ -110,19 +113,19 @@ Subscribes to the changes of this distributed data object. ...@@ -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.| | 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** **Example**
```js ```js
import distributedObject from '@ohos.data.distributedDataObject'; import distributedObject from '@ohos.data.distributedDataObject';
var g_object = distributedObject.createDistributedObject({name:"Amy", age:18, isVis:false, var g_object = distributedObject.createDistributedObject({name:"Amy", age:18, isVis:false,parent:{mother:"jack mom",father:"jack Dad"}});
parent:{mother:"jack mom",father:"jack Dad"}}); globalThis.changeCallback = (sessionId, changeData) => {
g_object.on("change", function (sessionId, changeData) { console.info("change" + sessionId);
console.info("change" + sessionId); if (changeData != null && changeData != undefined) {
if (changeData != null && changeData != undefined) { changeData.forEach(element => {
changeData.forEach(element => { console.info("changed !" + element + " " + g_object[element]);
console.info("changed !" + element + " " + g_object[element]); });
}); }
} }
}); g_object.on("change", globalThis.changeCallback);
``` ```
### off('change') ### off('change')
...@@ -140,20 +143,14 @@ Unsubscribes from the changes of this distributed data object. ...@@ -140,20 +143,14 @@ Unsubscribes from the changes of this distributed data object.
**Example** **Example**
```js ```js
import distributedObject from '@ohos.data.distributedDataObject'; import distributedObject from '@ohos.data.distributedDataObject';
var g_object = distributedObject.createDistributedObject({name:"Amy", age:18, isVis:false, var g_object = distributedObject.createDistributedObject({name:"Amy", age:18, isVis:false,parent:{mother:"jack mom",father:"jack Dad"}});
parent:{mother:"jack mom",father:"jack Dad"}}); // Unregister the specified data change callback.
g_object.on("change", function (sessionId, changeData) { g_object.off("change", globalThis.changeCallback);
console.info("change" + sessionId); // Unregister all data change callbacks.
}); g_object.off("change");
// 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");
```
### on('status') ### on('status')
...@@ -170,14 +167,14 @@ Subscribes to the status change (online or offline) of this distributed data obj ...@@ -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.| | 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** **Example**
```js ```js
import distributedObject from '@ohos.data.distributedDataObject'; import distributedObject from '@ohos.data.distributedDataObject';
var g_object = distributedObject.createDistributedObject({name:"Amy", age:18, isVis:false, globalThis.statusCallback = (sessionId, networkId, status) => {
parent:{mother:"jack mom",father:"jack Dad"}}); globalThis.response += "status changed " + sessionId + " " + status + " " + networkId;
g_object.on("status", function (sessionId, networkId, status) { }
this.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') ### off('status')
...@@ -196,15 +193,14 @@ Unsubscribes from the status change (online or offline) of this distributed data ...@@ -196,15 +193,14 @@ Unsubscribes from the status change (online or offline) of this distributed data
**Example** **Example**
```js ```js
import distributedObject from '@ohos.data.distributedDataObject'; import distributedObject from '@ohos.data.distributedDataObject';
g_object.on("status", function (sessionId, networkId, status) { var g_object = distributedObject.createDistributedObject({name:"Amy", age:18, isVis:false,parent:{mother:"jack mom",father:"jack Dad"}});
this.response += "status changed " + sessionId + " " + status + " " + networkId; 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", function (sessionId, networkId, status) { // Unsubscribe from the specified status change callback for the distributed data object.
this.response += "status changed " + sessionId + " " + status + " " + networkId; g_object.off("status",globalThis.statusCallback);
}); // Unsubscribe from all status change callbacks for the distributed data object.
// Unsubscribe from all status change callbacks for the distributed data object. g_object.off("status");
g_object.off("status"); ```
```
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册