提交 a17e2e9f 编写于 作者: W wangkai

change 1537

Signed-off-by: Nwangkai <wangkai424@huawei.com>
上级 e916ab09
......@@ -4513,26 +4513,42 @@ sync(deviceIds: string[], mode: SyncMode, delayMs?: number): void
**示例:**
```js
import deviceManager from '@ohos.distributedHardware.deviceManager';
let devManager;
let kvStore;
const KEY_TEST_SYNC_ELEMENT = 'key_test_sync';
const VALUE_TEST_SYNC_ELEMENT = 'value-string-001';
try {
kvStore.on('syncComplete', function (data) {
// create deviceManager
deviceManager.createDeviceManager('bundleName', (err, value) => {
if (!err) {
devManager = value;
let deviceIds = [];
if (devManager != null) {
var devices = devManager.getTrustedDeviceListSync();
for (var i = 0; i < devices.length; i++) {
deviceIds[i] = devices[i].deviceId;
}
}
try {
kvStore.on('syncComplete', function (data) {
console.log('Sync dataChange');
});
kvStore.put(KEY_TEST_SYNC_ELEMENT + 'testSync101', VALUE_TEST_SYNC_ELEMENT, function (err, data) {
});
kvStore.put(KEY_TEST_SYNC_ELEMENT + 'testSync101', VALUE_TEST_SYNC_ELEMENT, function (err, data) {
if (err != undefined) {
console.error(`Fail to sync.code is ${err.code},message is ${err.message}`);
return;
console.error(`Fail to sync.code is ${err.code},message is ${err.message}`);
return;
}
console.log('Succeeded in putting data');
const devices = ['deviceList'];
const mode = distributedKVStore.SyncMode.PULL_ONLY;
kvStore.sync(devices, mode, 1000);
});
} catch (e) {
console.error(`Fail to sync.code is ${e.code},message is ${e.message}`);
}
});
} catch (e) {
console.error(`Fail to sync.code is ${e.code},message is ${e.message}`);
}
}
});
```
### sync
......@@ -4569,17 +4585,31 @@ sync(deviceIds: string[], query: Query, mode: SyncMode, delayMs?: number): void
**示例:**
```js
import deviceManager from '@ohos.distributedHardware.deviceManager';
let devManager;
let kvStore;
const KEY_TEST_SYNC_ELEMENT = 'key_test_sync';
const VALUE_TEST_SYNC_ELEMENT = 'value-string-001';
try {
kvStore.on('syncComplete', function (data) {
// create deviceManager
deviceManager.createDeviceManager('bundleName', (err, value) => {
if (!err) {
devManager = value;
let deviceIds = [];
if (devManager != null) {
var devices = devManager.getTrustedDeviceListSync();
for (var i = 0; i < devices.length; i++) {
deviceIds[i] = devices[i].deviceId;
}
}
try {
kvStore.on('syncComplete', function (data) {
console.log('Sync dataChange');
});
kvStore.put(KEY_TEST_SYNC_ELEMENT + 'testSync101', VALUE_TEST_SYNC_ELEMENT, function (err, data) {
});
kvStore.put(KEY_TEST_SYNC_ELEMENT + 'testSync101', VALUE_TEST_SYNC_ELEMENT, function (err, data) {
if (err != undefined) {
console.error(`Fail to sync.code is ${err.code},message is ${err.message}`);
return;
console.error(`Fail to sync.code is ${err.code},message is ${err.message}`);
return;
}
console.log('Succeeded in putting data');
const devices = ['deviceList'];
......@@ -4588,10 +4618,12 @@ try {
query.prefixKey("batch_test");
query.deviceId('localDeviceId');
kvStore.sync(devices, query, mode, 1000);
});
} catch (e) {
console.error(`Fail to sync.code is ${e.code},message is ${e.message}`);
}
});
} catch (e) {
console.error(`Fail to sync.code is ${e.code},message is ${e.message}`);
}
}
});
```
### on('dataChange')
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册