From 223abcfc4bf7da2a374648aebb969a2ed390d524 Mon Sep 17 00:00:00 2001 From: "siyuan.liu" Date: Tue, 13 Sep 2022 11:18:25 +0800 Subject: [PATCH] update js-apis-distributed-data.md Signed-off-by: siyuan.liu --- .../apis/js-apis-distributed-data.md | 66 ++++++++----------- 1 file changed, 28 insertions(+), 38 deletions(-) diff --git a/zh-cn/application-dev/reference/apis/js-apis-distributed-data.md b/zh-cn/application-dev/reference/apis/js-apis-distributed-data.md index d67d2ed674..c8b7e3cdf9 100644 --- a/zh-cn/application-dev/reference/apis/js-apis-distributed-data.md +++ b/zh-cn/application-dev/reference/apis/js-apis-distributed-data.md @@ -72,28 +72,23 @@ FA模型下的示例: ```js import featureAbility from '@ohos.ability.featureAbility' let kvManager; -export default class MyAbility { - onCreate() { - console.log("MyAbilityStage onCreate") - let context = featureAbility.getContext() - const kvManagerConfig = { - context: context, - bundleName: 'com.example.datamanagertest', - userInfo: { - userId: '0', - userType: distributedData.UserType.SAME_USER_ID - } - } - distributedData.createKVManager(kvManagerConfig, function (err, manager) { - if (err) { - console.log("Failed to create KVManager: " + JSON.stringify(err)); - return; - } - console.log("Created KVManager"); - kvManager = manager; - }); +let context = featureAbility.getContext() +const kvManagerConfig = { + context: context, + bundleName: 'com.example.datamanagertest', + userInfo: { + userId: '0', + userType: distributedData.UserType.SAME_USER_ID } } +distributedData.createKVManager(kvManagerConfig, function (err, manager) { + if (err) { + console.log("Failed to create KVManager: " + JSON.stringify(err)); + return; + } + console.log("Created KVManager"); + kvManager = manager; +}); ``` ## distributedData.createKVManager @@ -148,26 +143,21 @@ FA模型下的示例: ```js import featureAbility from '@ohos.ability.featureAbility' let kvManager; -export default class MyAbility { - onCreate() { - console.log("MyAbilityStage onCreate") - let context = featureAbility.getContext() - const kvManagerConfig = { - context: context, - bundleName: 'com.example.datamanagertest', - userInfo: { - userId: '0', - userType: distributedData.UserType.SAME_USER_ID - } - } - distributedData.createKVManager(kvManagerConfig).then((manager) => { - console.log("Succeeded in creating KVManager"); - kvManager = manager; - }).catch((err) => { - console.log("Failed to create KVManager: " + JSON.stringify(err)); - }); +let context = featureAbility.getContext() +const kvManagerConfig = { + context: context, + bundleName: 'com.example.datamanagertest', + userInfo: { + userId: '0', + userType: distributedData.UserType.SAME_USER_ID } } +distributedData.createKVManager(kvManagerConfig).then((manager) => { + console.log("Succeeded in creating KVManager"); + kvManager = manager; +}).catch((err) => { + console.log("Failed to create KVManager: " + JSON.stringify(err)); +}); ``` ## KVManagerConfig -- GitLab