提交 223abcfc 编写于 作者: S siyuan.liu

update js-apis-distributed-data.md

Signed-off-by: Nsiyuan.liu <siyuan.liu@unionman.com.cn>
上级 e5c05ab2
...@@ -72,28 +72,23 @@ FA模型下的示例: ...@@ -72,28 +72,23 @@ FA模型下的示例:
```js ```js
import featureAbility from '@ohos.ability.featureAbility' import featureAbility from '@ohos.ability.featureAbility'
let kvManager; let kvManager;
export default class MyAbility { let context = featureAbility.getContext()
onCreate() { const kvManagerConfig = {
console.log("MyAbilityStage onCreate")
let context = featureAbility.getContext()
const kvManagerConfig = {
context: context, context: context,
bundleName: 'com.example.datamanagertest', bundleName: 'com.example.datamanagertest',
userInfo: { userInfo: {
userId: '0', userId: '0',
userType: distributedData.UserType.SAME_USER_ID userType: distributedData.UserType.SAME_USER_ID
} }
} }
distributedData.createKVManager(kvManagerConfig, function (err, manager) { distributedData.createKVManager(kvManagerConfig, function (err, manager) {
if (err) { if (err) {
console.log("Failed to create KVManager: " + JSON.stringify(err)); console.log("Failed to create KVManager: " + JSON.stringify(err));
return; return;
} }
console.log("Created KVManager"); console.log("Created KVManager");
kvManager = manager; kvManager = manager;
}); });
}
}
``` ```
## distributedData.createKVManager ## distributedData.createKVManager
...@@ -148,26 +143,21 @@ FA模型下的示例: ...@@ -148,26 +143,21 @@ FA模型下的示例:
```js ```js
import featureAbility from '@ohos.ability.featureAbility' import featureAbility from '@ohos.ability.featureAbility'
let kvManager; let kvManager;
export default class MyAbility { let context = featureAbility.getContext()
onCreate() { const kvManagerConfig = {
console.log("MyAbilityStage onCreate")
let context = featureAbility.getContext()
const kvManagerConfig = {
context: context, context: context,
bundleName: 'com.example.datamanagertest', bundleName: 'com.example.datamanagertest',
userInfo: { userInfo: {
userId: '0', userId: '0',
userType: distributedData.UserType.SAME_USER_ID userType: distributedData.UserType.SAME_USER_ID
} }
} }
distributedData.createKVManager(kvManagerConfig).then((manager) => { distributedData.createKVManager(kvManagerConfig).then((manager) => {
console.log("Succeeded in creating KVManager"); console.log("Succeeded in creating KVManager");
kvManager = manager; kvManager = manager;
}).catch((err) => { }).catch((err) => {
console.log("Failed to create KVManager: " + JSON.stringify(err)); console.log("Failed to create KVManager: " + JSON.stringify(err));
}); });
}
}
``` ```
## KVManagerConfig ## KVManagerConfig
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册