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 0e4818d2afd9945808f89d8704f539fb86ce1601..9108469149f87ad75973ac02caab20f5ce975cee 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 e525bc41b2ff32f200f90c9c62596628f2f32b53..64a399d30f428d342fadf30bedf3955282c42466 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