未验证 提交 c078d351 编写于 作者: O openharmony_ci 提交者: Gitee

!12179 amend revokeSave code demo

Merge pull request !12179 from wangxiyue/master
......@@ -560,15 +560,15 @@ save(deviceId: string, callback: AsyncCallback<SaveSuccessResponse>): void
**示例:**
```js
FA模型示例
```ts
import distributedObject from '@ohos.data.distributedDataObject';
import featureAbility from '@ohos.ability.featureAbility';
// 获取context
let context = featureAbility.getContext();
let g_object = distributedObject.create(context, {name:"Amy", age:18, isVis:false});
g_object.setSessionId("123456");
g_object.save("local", (status, result) => {
console.log("save status = " + status);
g_object.save("local", (result) => {
console.log("save callback");
console.info("save sessionId: " + result.sessionId);
console.info("save version: " + result.version);
......@@ -576,7 +576,8 @@ g_object.save("local", (status, result) => {
});
```
```js
Stage模型示例
```ts
import distributedObject from '@ohos.data.distributedDataObject';
import Ability from '@ohos.application.Ability';
// 获取context
......@@ -588,8 +589,7 @@ class MainAbility extends Ability{
}
let g_object = distributedObject.create(context, {name:"Amy", age:18, isVis:false});
g_object.setSessionId("123456");
g_object.save("local", (status, result) => {
console.log("save status = " + status);
g_object.save("local", (result) => {
console.log("save callback");
console.info("save sessionId: " + result.sessionId);
console.info("save version: " + result.version);
......@@ -694,13 +694,17 @@ import featureAbility from '@ohos.ability.featureAbility';
let context = featureAbility.getContext();
let g_object = distributedObject.create(context, {name:"Amy", age:18, isVis:false});
g_object.setSessionId("123456");
g_object.save("local").then((result) => {
// 持久化数据
g_object.save("local", (result) => {
console.log("save callback");
console.info("save sessionId " + result.sessionId);
console.info("save version " + result.version);
console.info("save deviceId " + result.deviceId);
}, () => {
console.error("save failed");
});
// 删除持久化保存的数据
g_object.revokeSave((result) => {
console.log("revokeSave callback");
console.log("revokeSave sessionId " + result.sessionId);
});
```
......@@ -711,15 +715,24 @@ import distributedObject from '@ohos.data.distributedDataObject';
import Ability from '@ohos.application.Ability';
// 获取context
let context;
class MainAbility extends Ability{
onWindowStageCreate(windowStage){
class MainAbility extends Ability {
onWindowStageCreate(windowStage) {
context = this.context
}
}
let g_object = distributedObject.create(context, {name:"Amy", age:18, isVis:false});
g_object.setSessionId("123456");
g_object.revokeSave((result, data) => {
// 持久化数据
g_object.save("local", (result) => {
console.log("save callback");
console.info("save sessionId " + result.sessionId);
console.info("save version " + result.version);
console.info("save deviceId " + result.deviceId);
});
// 删除持久化保存的数据
g_object.revokeSave((result) => {
console.log("revokeSave callback");
console.log("revokeSave sessionId " + result.sessionId);
});
```
......@@ -744,13 +757,23 @@ revokeSave(): Promise<RevokeSaveSuccessResponse>
FA模型示例
```js
```ts
import distributedObject from '@ohos.data.distributedDataObject';
import featureAbility from '@ohos.ability.featureAbility';
// 获取context
let context = featureAbility.getContext();
let g_object = distributedObject.create(context, {name:"Amy", age:18, isVis:false});
g_object.setSessionId("123456");
// 持久化数据
g_object.save("local").then((result) => {
console.log("save callback");
console.info("save sessionId " + result.sessionId);
console.info("save version " + result.version);
console.info("save deviceId " + result.deviceId);
}, () => {
console.error("save failed");
});
// 删除持久化保存的数据
g_object.revokeSave().then((result) => {
console.log("revokeSave callback");
console.log("sessionId" + result.sessionId);
......@@ -766,8 +789,8 @@ import distributedObject from '@ohos.data.distributedDataObject';
import Ability from '@ohos.application.Ability';
// 获取context
let context;
class MainAbility extends Ability{
onWindowStageCreate(windowStage){
class MainAbility extends Ability {
onWindowStageCreate(windowStage) {
context = this.context
}
}
......@@ -781,6 +804,14 @@ g_object.save("local").then((result) => {
}, () => {
console.error("save failed");
});
// 删除持久化保存的数据
g_object.revokeSave().then((result) => {
console.log("revokeSave callback");
console.log("sessionId" + result.sessionId);
}, () => {
console.error("revokeSave failed");
});
```
## distributedObject.createDistributedObject<sup>(deprecated)</sup>
......@@ -985,4 +1016,4 @@ globalThis.statusCallback = (sessionId, networkId, status) => {
g_object.off("status",globalThis.statusCallback);
// 删除所有的上下线回调
g_object.off("status");
```
\ No newline at end of file
```
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册