Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Docs
提交
629b0425
D
Docs
项目概览
OpenHarmony
/
Docs
1 年多 前同步成功
通知
159
Star
292
Fork
28
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
D
Docs
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
629b0425
编写于
10月 08, 2022
作者:
A
Annie_wang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
update docs
Signed-off-by:
N
Annie_wang
<
annie.wangli@huawei.com
>
上级
af822aea
变更
2
展开全部
隐藏空白更改
内联
并排
Showing
2 changed file
with
211 addition
and
191 deletion
+211
-191
en/application-dev/database/database-mdds-guidelines.md
en/application-dev/database/database-mdds-guidelines.md
+62
-25
en/application-dev/reference/apis/js-apis-distributed-data.md
...pplication-dev/reference/apis/js-apis-distributed-data.md
+149
-166
未找到文件。
en/application-dev/database/database-mdds-guidelines.md
浏览文件 @
629b0425
...
@@ -50,18 +50,41 @@ The following uses a single KV store as an example to describe the development p
...
@@ -50,18 +50,41 @@ The following uses a single KV store as an example to describe the development p
This permission must also be granted by the user when the application is started for the first time. The sample code is as follows:
This permission must also be granted by the user when the application is started for the first time. The sample code is as follows:
```js
```js
// FA model
import featureAbility from '@ohos.ability.featureAbility';
import featureAbility from '@ohos.ability.featureAbility';
function grantPermission() {
function grantPermission() {
console.info('grantPermission');
console.info('grantPermission');
let context = featureAbility.getContext();
let context = featureAbility.getContext();
context.requestPermissionsFromUser(['ohos.permission.DISTRIBUTED_DATASYNC'], 666, function (result)
{
context.requestPermissionsFromUser(['ohos.permission.DISTRIBUTED_DATASYNC'], 666).then((data) =>
{
console.info(`result.requestCode=${result.requestCode}`)
console.info('success: ${data}');
}).catch((error) => {
})
console.info('failed: ${error}');
console.info('end grantPermission');
})
}
}
grantPermission();
// Stage model
import Ability from '@ohos.application.Ability';
let context = null;
function grantPermission() {
class MainAbility extends Ability {
onWindowStageCreate(windowStage) {
let context = this.context;
}
}
let permissions = ['ohos.permission.DISTRIBUTED_DATASYNC'];
context.requestPermissionsFromUser(permissions).then((data) => {
console.log('success: ${data}');
}).catch((error) => {
console.log('failed: ${error}');
});
}
grantPermission();
grantPermission();
```
```
...
@@ -73,25 +96,39 @@ The following uses a single KV store as an example to describe the development p
...
@@ -73,25 +96,39 @@ The following uses a single KV store as an example to describe the development p
The sample code is as follows:
The sample code is as follows:
```
js
```
js
// Obtain the context of the FA model.
import
featureAbility
from
'
@ohos.ability.featureAbility
'
;
let
context
=
featureAbility
.
getContext
();
// Obtain the context of the stage model.
import
AbilityStage
from
'
@ohos.application.Ability
'
;
let
context
=
null
;
class
MainAbility
extends
AbilityStage
{
onWindowStageCreate
(
windowStage
){
context
=
this
.
context
;
}
}
let
kvManager
;
let
kvManager
;
try
{
try
{
const
kvManagerConfig
=
{
const
kvManagerConfig
=
{
bundleName
:
'
com.example.datamanagertest
'
,
bundleName
:
'
com.example.datamanagertest
'
,
userInfo
:
{
userInfo
:
{
context
:
context
,
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
(
"
createKVManager err:
"
+
JSON
.
stringify
(
err
)
);
console
.
log
(
'
Failed to create KVManager: ${error}
'
);
return
;
return
;
}
}
console
.
log
(
"
createKVManager success
"
);
console
.
log
(
'
Created KVManager successfully
'
);
kvManager
=
manager
;
kvManager
=
manager
;
});
});
}
catch
(
e
)
{
}
catch
(
e
)
{
console
.
log
(
"
An unexpected error occurred. Error:
"
+
e
);
console
.
log
(
'
An unexpected error occurred. Error: ${e}
'
);
}
}
```
```
...
@@ -115,14 +152,14 @@ The following uses a single KV store as an example to describe the development p
...
@@ -115,14 +152,14 @@ The following uses a single KV store as an example to describe the development p
};
};
kvManager
.
getKVStore
(
'
storeId
'
,
options
,
function
(
err
,
store
)
{
kvManager
.
getKVStore
(
'
storeId
'
,
options
,
function
(
err
,
store
)
{
if
(
err
)
{
if
(
err
)
{
console
.
log
(
"
getKVStore err:
"
+
JSON
.
stringify
(
err
)
);
console
.
log
(
'
Failed to get KVStore: ${err}
'
);
return
;
return
;
}
}
console
.
log
(
"
getKVStore success
"
);
console
.
log
(
'
Got KVStore successfully
'
);
kvStore
=
store
;
kvStore
=
store
;
});
});
}
catch
(
e
)
{
}
catch
(
e
)
{
console
.
log
(
"
An unexpected error occurred. Error:
"
+
e
);
console
.
log
(
'
An unexpected error occurred. Error: ${e}
'
);
}
}
```
```
...
@@ -136,7 +173,7 @@ The following uses a single KV store as an example to describe the development p
...
@@ -136,7 +173,7 @@ The following uses a single KV store as an example to describe the development p
```
js
```
js
kvStore
.
on
(
'
dataChange
'
,
distributedData
.
SubscribeType
.
SUBSCRIBE_TYPE_ALL
,
function
(
data
)
{
kvStore
.
on
(
'
dataChange
'
,
distributedData
.
SubscribeType
.
SUBSCRIBE_TYPE_ALL
,
function
(
data
)
{
console
.
log
(
"
dataChange callback call data:
"
+
JSON
.
stringify
(
data
)
);
console
.
log
(
"
dataChange callback call data:
${data}
"
);
});
});
```
```
...
@@ -153,13 +190,13 @@ The following uses a single KV store as an example to describe the development p
...
@@ -153,13 +190,13 @@ The following uses a single KV store as an example to describe the development p
try
{
try
{
kvStore
.
put
(
KEY_TEST_STRING_ELEMENT
,
VALUE_TEST_STRING_ELEMENT
,
function
(
err
,
data
)
{
kvStore
.
put
(
KEY_TEST_STRING_ELEMENT
,
VALUE_TEST_STRING_ELEMENT
,
function
(
err
,
data
)
{
if
(
err
!=
undefined
)
{
if
(
err
!=
undefined
)
{
console
.
log
(
"
put err:
"
+
JSON
.
stringify
(
err
)
);
console
.
log
(
'
Failed to put data: ${error}
'
);
return
;
return
;
}
}
console
.
log
(
"
put success
"
);
console
.
log
(
'
Put data successfully
'
);
});
});
}
catch
(
e
)
{
}
catch
(
e
)
{
console
.
log
(
"
An unexpected error occurred. Error:
"
+
e
);
console
.
log
(
'
An unexpected error occurred. Error: ${e}
'
);
}
}
```
```
...
@@ -176,16 +213,16 @@ The following uses a single KV store as an example to describe the development p
...
@@ -176,16 +213,16 @@ The following uses a single KV store as an example to describe the development p
try
{
try
{
kvStore
.
put
(
KEY_TEST_STRING_ELEMENT
,
VALUE_TEST_STRING_ELEMENT
,
function
(
err
,
data
)
{
kvStore
.
put
(
KEY_TEST_STRING_ELEMENT
,
VALUE_TEST_STRING_ELEMENT
,
function
(
err
,
data
)
{
if
(
err
!=
undefined
)
{
if
(
err
!=
undefined
)
{
console
.
log
(
"
put err:
"
+
JSON
.
stringify
(
err
)
);
console
.
log
(
'
Failed to put data: ${error}
'
);
return
;
return
;
}
}
console
.
log
(
"
put success
"
);
console
.
log
(
'
Put data successfully
'
);
kvStore
.
get
(
KEY_TEST_STRING_ELEMENT
,
function
(
err
,
data
)
{
kvStore
.
get
(
KEY_TEST_STRING_ELEMENT
,
function
(
err
,
data
)
{
console
.
log
(
"
get success data:
"
+
data
);
console
.
log
(
'
Got data successfully: ${data}
'
);
});
});
});
});
}
catch
(
e
)
{
}
catch
(
e
)
{
console
.
log
(
"
An unexpected error occurred. Error:
"
+
e
);
console
.
log
(
'
An unexpected error occurred. Error: ${e}
'
);
}
}
```
```
...
@@ -204,7 +241,7 @@ The following uses a single KV store as an example to describe the development p
...
@@ -204,7 +241,7 @@ The following uses a single KV store as an example to describe the development p
let
devManager
;
let
devManager
;
// Create deviceManager.
// Create deviceManager.
deviceManager
.
createDeviceManager
(
"
bundleName
"
,
(
err
,
value
)
=>
{
deviceManager
.
createDeviceManager
(
'
bundleName
'
,
(
err
,
value
)
=>
{
if
(
!
err
)
{
if
(
!
err
)
{
devManager
=
value
;
devManager
=
value
;
// deviceIds is obtained by deviceManager by calling getTrustedDeviceListSync().
// deviceIds is obtained by deviceManager by calling getTrustedDeviceListSync().
...
@@ -219,7 +256,7 @@ The following uses a single KV store as an example to describe the development p
...
@@ -219,7 +256,7 @@ The following uses a single KV store as an example to describe the development p
// 1000 indicates that the maximum delay is 1000 ms.
// 1000 indicates that the maximum delay is 1000 ms.
kvStore
.
sync
(
deviceIds
,
distributedData
.
SyncMode
.
PUSH_ONLY
,
1000
);
kvStore
.
sync
(
deviceIds
,
distributedData
.
SyncMode
.
PUSH_ONLY
,
1000
);
}
catch
(
e
)
{
}
catch
(
e
)
{
console
.
log
(
"
An unexpected error occurred. Error:
"
+
e
);
console
.
log
(
'
An unexpected error occurred. Error: ${e}
'
);
}
}
}
}
});
});
...
...
en/application-dev/reference/apis/js-apis-distributed-data.md
浏览文件 @
629b0425
此差异已折叠。
点击以展开。
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录