From 41b33de5dcf6e124484128a3195ba5bfeb7e2eda Mon Sep 17 00:00:00 2001 From: wangkai Date: Mon, 28 Aug 2023 11:41:59 +0800 Subject: [PATCH] arkts check Signed-off-by: wangkai --- .../database/unified-data-channels.md | 130 ++++++++++-------- .../database/unified-data-definition.md | 4 +- 2 files changed, 71 insertions(+), 63 deletions(-) diff --git a/zh-cn/application-dev/database/unified-data-channels.md b/zh-cn/application-dev/database/unified-data-channels.md index 3d4b0574e6..8ec7363760 100644 --- a/zh-cn/application-dev/database/unified-data-channels.md +++ b/zh-cn/application-dev/database/unified-data-channels.md @@ -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 = (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 = (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} `); } ``` diff --git a/zh-cn/application-dev/database/unified-data-definition.md b/zh-cn/application-dev/database/unified-data-definition.md index 8db772d70c..fe519513ed 100644 --- a/zh-cn/application-dev/database/unified-data-definition.md +++ b/zh-cn/application-dev/database/unified-data-definition.md @@ -114,11 +114,11 @@ UDMF提供了统一数据对象UnifiedData,用于封装一组数据记录Unifi switch (type) { case uniformTypeDescriptor.UniformDataType.IMAGE: // 转换得到原图片数据记录 - let image = (records[i]); + let image = records[i] as unifiedDataChannel.Image; break; case uniformTypeDescriptor.UniformDataType.PLAIN_TEXT: // 转换得到原文本数据记录 - let plainText = (records[i]); + let plainText = records[i] as unifiedDataChannel.PlainText; break; default: break; -- GitLab