From 956156b32a37fac71050fb45d22d852598315e0f Mon Sep 17 00:00:00 2001 From: liusaimei Date: Fri, 7 Jul 2023 16:37:43 +0800 Subject: [PATCH] modify datashare Signed-off-by: liusaimei --- .../reference/apis/js-apis-data-dataShare.md | 16 ++------------ .../changelogs-datashare.md | 22 +++++++++---------- 2 files changed, 13 insertions(+), 25 deletions(-) diff --git a/zh-cn/application-dev/reference/apis/js-apis-data-dataShare.md b/zh-cn/application-dev/reference/apis/js-apis-data-dataShare.md index 0e4818d2af..9108469149 100644 --- a/zh-cn/application-dev/reference/apis/js-apis-data-dataShare.md +++ b/zh-cn/application-dev/reference/apis/js-apis-data-dataShare.md @@ -558,25 +558,13 @@ publish(data: Array<PublishedItem>, bundleName: string, version: number, c **示例:** ```ts -let arrayBuffer = null; -let subscriberId = '11'; +let arrayBuffer = new ArrayBuffer(1); let version = 1; -let data : Array = [ - {key:"city", subscriberId:"11", data:"xian"}, - {key:"datashareproxy://com.acts.ohos.data.datasharetest/appInfo", subscriberId:"11", data:"appinfo is just a test app"}, - {key:"empty", subscriberId:"11", data:"nobody sub"}]; -let nums:number[] = [1,2,3]; +let data : Array = [{key:"key2", subscriberId:"11", data:arrayBuffer}]; function publishCallback(err, result: Array) { console.info("publishCallback " + JSON.stringify(result)); } try { - arrayBuffer = new ArrayBuffer(nums.length); - let array:Uint8Array = new Uint8Array(arrayBuffer); - data.push({ - "key" : "key2", - "data" : array, - "subscriberId" : "11", - }); console.info("data length is:", data.length); dataShareHelper.publish(data, "com.acts.ohos.data.datasharetest", version, publishCallback); } catch (e) { diff --git a/zh-cn/release-notes/changelogs/OpenHarmony_4.0.8.2/changelogs-datashare.md b/zh-cn/release-notes/changelogs/OpenHarmony_4.0.8.2/changelogs-datashare.md index e525bc41b2..64a399d30f 100644 --- a/zh-cn/release-notes/changelogs/OpenHarmony_4.0.8.2/changelogs-datashare.md +++ b/zh-cn/release-notes/changelogs/OpenHarmony_4.0.8.2/changelogs-datashare.md @@ -24,16 +24,16 @@ PublishedItem中data的数据类型从Ashmem变更为ArrayBuffer **示例:** ```ts -function onPublishCallback(err, node:dataShare.PublishedDataChangeNode) { - for (let i = 0; i < node.data.length; i++) { - if (typeof node.data[i].data != 'string') { - let array:ArrayBuffer = node.data[i].data; - let data:Uint8Array = new Uint8Array(array); - console.info("onPublishCallback " + JSON.stringify(data)); - } - } +let arrayBuffer = new ArrayBuffer(1); +let version = 1; +let data : Array = [{key:"key2", subscriberId:"11", data:arrayBuffer}]; +function publishCallback(err, result: Array) { + console.info("publishCallback " + JSON.stringify(result)); +} +try { + console.info("data length is:", data.length); + dataShareHelper.publish(data, "com.acts.ohos.data.datasharetest", version, publishCallback); +} catch (e) { + console.error("publish error " + JSON.stringify(e)); } -let uris:Array = ['city', 'datashareproxy://com.acts.ohos.data.datasharetest/appInfo', 'key2']; -let subscriberId = '11'; -let result: Array = dataShareHelper.on('publishedDataChange', uris, subscriberId, onPublishCallback); ``` \ No newline at end of file -- GitLab