Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Docs
提交
41b33de5
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看板
提交
41b33de5
编写于
8月 28, 2023
作者:
W
wangkai
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
arkts check
Signed-off-by:
N
wangkai
<
wangkai424@huawei.com
>
上级
61b7ef48
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
71 addition
and
63 deletion
+71
-63
zh-cn/application-dev/database/unified-data-channels.md
zh-cn/application-dev/database/unified-data-channels.md
+69
-61
zh-cn/application-dev/database/unified-data-definition.md
zh-cn/application-dev/database/unified-data-definition.md
+2
-2
未找到文件。
zh-cn/application-dev/database/unified-data-channels.md
浏览文件 @
41b33de5
...
...
@@ -54,77 +54,83 @@ UDMF针对多对多跨应用数据共享的不同业务场景提供了标准化
2.
创建一个统一数据对象并插入到UDMF的公共数据通路中。
```
ts
import
{
BusinessError
}
from
'
@ohos.base
'
;
let
plainText
=
new
unifiedDataChannel
.
PlainText
();
plainText
.
textContent
=
'
hello world!
'
;
let
unifiedData
=
new
unifiedDataChannel
.
UnifiedData
(
plainText
);
// 指定要插入数据的数据通路枚举类型
let
options
=
{
intention
:
unifiedDataChannel
.
Intention
.
DATA_HUB
let
options
:
unifiedDataChannel
.
Options
=
{
intention
:
unifiedDataChannel
.
Intention
.
DATA_HUB
}
try
{
unifiedDataChannel
.
insertData
(
options
,
unifiedData
,
(
err
,
data
)
=>
{
if
(
err
===
undefined
)
{
console
.
info
(
`Succeeded in inserting data. key =
${
data
}
`
);
}
else
{
console
.
error
(
`Failed to insert data. code is
${
err
.
code
}
,message is
${
err
.
message
}
`
);
}
});
}
catch
(
e
)
{
console
.
error
(
`Insert data throws an exception. code is
${
e
.
code
}
,message is
${
e
.
message
}
`
);
unifiedDataChannel
.
insertData
(
options
,
unifiedData
,
(
err
,
data
)
=>
{
if
(
err
===
undefined
)
{
console
.
info
(
`Succeeded in inserting data. key =
${
data
}
`
);
}
else
{
console
.
error
(
`Failed to insert data. code is
${
err
.
code
}
,message is
${
err
.
message
}
`
);
}
});
}
catch
(
e
)
{
let
error
:
BusinessError
=
e
as
BusinessError
;
console
.
error
(
`Insert data throws an exception. code is
${
error
.
code
}
,message is
${
error
.
message
}
`
);
}
```
3.
更新上一步骤插入的统一数据对象。
```
ts
import
{
BusinessError
}
from
'
@ohos.base
'
;
let
plainText
=
new
unifiedDataChannel
.
PlainText
();
plainText
.
textContent
=
'
How are you!
'
;
let
unifiedData
=
new
unifiedDataChannel
.
UnifiedData
(
plainText
);
// 指定要更新的统一数据对象的URI
let
options
=
{
key
:
'
udmf://DataHub/com.ohos.test/0123456789
'
let
options
:
unifiedDataChannel
.
Options
=
{
key
:
'
udmf://DataHub/com.ohos.test/0123456789
'
};
try
{
unifiedDataChannel
.
updateData
(
options
,
unifiedData
,
(
err
)
=>
{
if
(
err
===
undefined
)
{
console
.
info
(
'
Succeeded in updating data.
'
);
}
else
{
console
.
error
(
`Failed to update data. code is
${
err
.
code
}
,message is
${
err
.
message
}
`
);
}
});
}
catch
(
e
)
{
console
.
error
(
`Update data throws an exception. code is
${
e
.
code
}
,message is
${
e
.
message
}
`
);
unifiedDataChannel
.
updateData
(
options
,
unifiedData
,
(
err
)
=>
{
if
(
err
===
undefined
)
{
console
.
info
(
'
Succeeded in updating data.
'
);
}
else
{
console
.
error
(
`Failed to update data. code is
${
err
.
code
}
,message is
${
err
.
message
}
`
);
}
});
}
catch
(
e
)
{
let
error
:
BusinessError
=
e
as
BusinessError
;
console
.
error
(
`Update data throws an exception. code is
${
error
.
code
}
,message is
${
error
.
message
}
`
);
}
```
4.
删除存储在UDMF公共数据通路中的统一数据对象。
```
ts
import
{
BusinessError
}
from
'
@ohos.base
'
;
// 指定要删除数据的数据通路枚举类型
let
options
=
{
intention
:
unifiedDataChannel
.
Intention
.
DATA_HUB
let
options
:
unifiedDataChannel
.
Options
=
{
intention
:
unifiedDataChannel
.
Intention
.
DATA_HUB
};
try
{
unifiedDataChannel
.
deleteData
(
options
,
(
err
,
data
)
=>
{
if
(
err
===
undefined
)
{
console
.
info
(
`Succeeded in deleting data. size =
${
data
.
length
}
`
);
for
(
let
i
=
0
;
i
<
data
.
length
;
i
++
)
{
let
records
=
data
[
i
].
getRecords
();
for
(
let
j
=
0
;
j
<
records
.
length
;
j
++
)
{
if
(
records
[
j
].
getType
()
===
uniformTypeDescriptor
.
UniformDataType
.
PLAIN_TEXT
)
{
let
text
=
<
unifiedDataChannel
.
PlainText
>
(
records
[
j
]);
console
.
info
(
`
${
i
+
1
}
.
${
text
.
textContent
}
`
);
}
}
}
}
else
{
console
.
error
(
`Failed to delete data. code is
${
err
.
code
}
,message is
${
err
.
message
}
`
);
unifiedDataChannel
.
deleteData
(
options
,
(
err
,
data
)
=>
{
if
(
err
===
undefined
)
{
console
.
info
(
`Succeeded in deleting data. size =
${
data
.
length
}
`
);
for
(
let
i
=
0
;
i
<
data
.
length
;
i
++
)
{
let
records
=
data
[
i
].
getRecords
();
for
(
let
j
=
0
;
j
<
records
.
length
;
j
++
)
{
if
(
records
[
j
].
getType
()
===
uniformTypeDescriptor
.
UniformDataType
.
PLAIN_TEXT
)
{
let
text
=
records
[
j
]
as
unifiedDataChannel
.
PlainText
;
console
.
info
(
`
${
i
+
1
}
.
${
text
.
textContent
}
`
);
}
}
});
}
catch
(
e
)
{
console
.
error
(
`Delete data throws an exception. code is
${
e
.
code
}
,message is
${
e
.
message
}
`
);
}
}
else
{
console
.
error
(
`Failed to delete data. code is
${
err
.
code
}
,message is
${
err
.
message
}
`
);
}
});
}
catch
(
e
)
{
let
error
:
BusinessError
=
e
as
BusinessError
;
console
.
error
(
`Delete data throws an exception. code is
${
error
.
code
}
,message is
${
error
.
message
}
`
);
}
```
...
...
@@ -139,29 +145,31 @@ UDMF针对多对多跨应用数据共享的不同业务场景提供了标准化
2.
查询存储在UDMF公共数据通路中的统一数据对象。
```
ts
import
{
BusinessError
}
from
'
@ohos.base
'
;
// 指定要查询数据的数据通路枚举类型
let
options
=
{
intention
:
unifiedDataChannel
.
Intention
.
DATA_HUB
let
options
:
unifiedDataChannel
.
Options
=
{
intention
:
unifiedDataChannel
.
Intention
.
DATA_HUB
};
try
{
unifiedDataChannel
.
queryData
(
options
,
(
err
,
data
)
=>
{
if
(
err
===
undefined
)
{
console
.
info
(
`Succeeded in querying data. size =
${
data
.
length
}
`
);
for
(
let
i
=
0
;
i
<
data
.
length
;
i
++
)
{
let
records
=
data
[
i
].
getRecords
();
for
(
let
j
=
0
;
j
<
records
.
length
;
j
++
)
{
if
(
records
[
j
].
getType
()
===
uniformTypeDescriptor
.
UniformDataType
.
PLAIN_TEXT
)
{
let
text
=
<
unifiedDataChannel
.
PlainText
>
(
records
[
j
]);
console
.
info
(
`
${
i
+
1
}
.
${
text
.
textContent
}
`
);
}
}
}
}
else
{
console
.
error
(
`Failed to query data. code is
${
err
.
code
}
,message is
${
err
.
message
}
`
);
unifiedDataChannel
.
queryData
(
options
,
(
err
,
data
)
=>
{
if
(
err
===
undefined
)
{
console
.
info
(
`Succeeded in querying data. size =
${
data
.
length
}
`
);
for
(
let
i
=
0
;
i
<
data
.
length
;
i
++
)
{
let
records
=
data
[
i
].
getRecords
();
for
(
let
j
=
0
;
j
<
records
.
length
;
j
++
)
{
if
(
records
[
j
].
getType
()
===
uniformTypeDescriptor
.
UniformDataType
.
PLAIN_TEXT
)
{
let
text
=
records
[
j
]
as
unifiedDataChannel
.
PlainText
;
console
.
info
(
`
${
i
+
1
}
.
${
text
.
textContent
}
`
);
}
}
});
}
}
else
{
console
.
error
(
`Failed to query data. code is
${
err
.
code
}
,message is
${
err
.
message
}
`
);
}
});
}
catch
(
e
)
{
console
.
error
(
`Query data throws an exception. code is
${
e
.
code
}
,message is
${
e
.
message
}
`
);
let
error
:
BusinessError
=
e
as
BusinessError
;
console
.
error
(
`Query data throws an exception. code is
${
error
.
code
}
,message is
${
error
.
message
}
`
);
}
```
zh-cn/application-dev/database/unified-data-definition.md
浏览文件 @
41b33de5
...
...
@@ -114,11 +114,11 @@ UDMF提供了统一数据对象UnifiedData,用于封装一组数据记录Unifi
switch
(
type
)
{
case
uniformTypeDescriptor
.
UniformDataType
.
IMAGE
:
// 转换得到原图片数据记录
let
image
=
<
unifiedDataChannel
.
Image
>
(
records
[
i
])
;
let
image
=
records
[
i
]
as
unifiedDataChannel
.
Image
;
break
;
case
uniformTypeDescriptor
.
UniformDataType
.
PLAIN_TEXT
:
// 转换得到原文本数据记录
let
plainText
=
<
unifiedDataChannel
.
PlainText
>
(
records
[
i
])
;
let
plainText
=
records
[
i
]
as
unifiedDataChannel
.
PlainText
;
break
;
default
:
break
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录