提交 f0b91ba3 编写于 作者: A Annie_wang

update docs

Signed-off-by: NAnnie_wang <annie.wangli@huawei.com>
上级 aff329ec
......@@ -61,7 +61,7 @@ export default class MyAbilityStage extends AbilityStage {
console.log("Failed to create KVManager: " + JSON.stringify(err));
return;
}
console.log("Created KVManager");
console.log("Created KVManager successfully");
kvManager = manager;
});
}
......@@ -89,7 +89,7 @@ export default class MyAbilityStage extends AbilityStage {
console.log("Failed to create KVManager: " + JSON.stringify(err));
return;
}
console.log("Created KVManager");
console.log("Created KVManager successfully");
kvManager = manager;
});
}
......@@ -139,7 +139,7 @@ export default class MyAbilityStage extends AbilityStage {
console.log("Failed to create KVManager: " + JSON.stringify(err));
return;
}
console.log("Created KVManager");
console.log("Created KVManager successfully");
kvManager = manager;
});
}
......@@ -167,7 +167,7 @@ export default class MyAbilityStage extends AbilityStage {
console.log("Failed to create KVManager: " + JSON.stringify(err));
return;
}
console.log("Created KVManager");
console.log("Created KVManager successfully");
kvManager = manager;
});
}
......@@ -304,7 +304,7 @@ try {
}
```
### closeKVStore<sup>8+</sup> ###
### closeKVStore<sup>8+</sup>
closeKVStore(appId: string, storeId: string, kvStore: KVStore, callback: AsyncCallback&lt;void&gt;): void
......@@ -350,7 +350,7 @@ const options = {
```
### closeKVStore<sup>8+</sup> ###
### closeKVStore<sup>8+</sup>
closeKVStore(appId: string, storeId: string, kvStore: KVStore): Promise&lt;void&gt;
......@@ -404,7 +404,7 @@ const options = {
```
### deleteKVStore<sup>8+</sup> ###
### deleteKVStore<sup>8+</sup>
deleteKVStore(appId: string, storeId: string, callback: AsyncCallback&lt;void&gt;): void
......@@ -447,7 +447,7 @@ try {
}
```
### deleteKVStore<sup>8+</sup> ###
### deleteKVStore<sup>8+</sup>
deleteKVStore(appId: string, storeId: string): Promise&lt;void&gt;
......@@ -501,7 +501,7 @@ try {
```
### getAllKVStoreId<sup>8+</sup> ###
### getAllKVStoreId<sup>8+</sup>
getAllKVStoreId(appId: string, callback: AsyncCallback&lt;string[]&gt;): void
......@@ -531,7 +531,7 @@ try {
```
### getAllKVStoreId<sup>8+</sup> ###
### getAllKVStoreId<sup>8+</sup>
getAllKVStoreId(appId: string): Promise&lt;string[]&gt;
......@@ -570,7 +570,7 @@ try {
```
### on('distributedDataServiceDie')<sup>8+</sup> ###
### on('distributedDataServiceDie')<sup>8+</sup>
on(event: 'distributedDataServiceDie', deathCallback: Callback&lt;void&gt;): void
......@@ -582,8 +582,8 @@ Subscribes to service status changes.
| Name | Type| Mandatory | Description |
| ----- | ------ | ---- | ----------------------- |
| event | string | Yes | Event to subscribe to. The value is **distributedDataServiceDie**, which indicates service status changes.|
| deathCallback | Callback&lt;void&gt; | Yes | Callback invoked to return service status changes.|
| event | string | Yes | Event to subscribe to. The value is **distributedDataServiceDie**, which indicates a service status change event.|
| deathCallback | Callback&lt;void&gt; | Yes | Callback invoked to return a service status change event.|
**Example**
......@@ -602,11 +602,11 @@ try {
```
### off('distributedDataServiceDie')<sup>8+</sup> ###
### off('distributedDataServiceDie')<sup>8+</sup>
off(event: 'distributedDataServiceDie', deathCallback?: Callback&lt;void&gt;): void
Unsubscribes from the service status changes.
Unsubscribes from service status changes.
**System capability**: SystemCapability.DistributedDataManager.KVStore.DistributedKVStore
......@@ -614,8 +614,8 @@ Unsubscribes from the service status changes.
| Name | Type| Mandatory | Description |
| ----- | ------ | ---- | ----------------------- |
| event | string | Yes | Event to unsubscribe from. The value is **distributedDataServiceDie**, which indicates service status changes.|
| deathCallback | Callback&lt;void&gt; | No | Callback used to return service status changes.|
| event | string | Yes | Event to unsubscribe from. The value is **distributedDataServiceDie**, which indicates a service status change event.|
| deathCallback | Callback&lt;void&gt; | No | Callback used to return a service status change event.|
**Example**
......@@ -706,7 +706,7 @@ Defines the schema of a KV store. You can create a **Schema** object and place i
| mode<sup>8+</sup> | number | Schema mode. |
| skip<sup>8+</sup> | number | Size of a skip of the schema. |
### constructor<sup>8+</sup> ###
### constructor<sup>8+</sup>
constructor()
......@@ -726,7 +726,7 @@ Represents a **Schema** instance, which provides the methods for defining the va
| default<sup>8+</sup> | string | Default value of a **FieldNode**.|
| type<sup>8+</sup> | number | Value of the data type corresponding to the specified node.|
### constructor<sup>8+</sup> ###
### constructor<sup>8+</sup>
constructor(name: string)
......@@ -740,7 +740,7 @@ A constructor used to create a **FieldNode** instance with a string field.
| ------ | -------- | ---- | --------------- |
| name | string | Yes | Value of **FieldNode**.|
### appendChild<sup>8+</sup> ###
### appendChild<sup>8+</sup>
appendChild(child: FieldNode): boolean
......@@ -790,7 +790,7 @@ Provides methods to obtain the KV store result sets, and query and move the data
Before calling any method in **KvStoreResultSet**, you must use [getKVStore](#getkvstore) to obtain a **KVStore** object.
### getCount<sup>8+</sup> ###
### getCount<sup>8+</sup>
getCount(): number
......@@ -823,7 +823,7 @@ try {
}
```
### getPosition<sup>8+</sup> ###
### getPosition<sup>8+</sup>
getPosition(): number
......@@ -857,7 +857,7 @@ try {
```
### moveToFirst<sup>8+</sup> ###
### moveToFirst<sup>8+</sup>
moveToFirst(): boolean
......@@ -891,7 +891,7 @@ try {
```
### moveToLast<sup>8+</sup> ###
### moveToLast<sup>8+</sup>
moveToLast(): boolean
......@@ -925,7 +925,7 @@ try {
```
### moveToNext<sup>8+</sup> ###
### moveToNext<sup>8+</sup>
moveToNext(): boolean
......@@ -959,7 +959,7 @@ try {
```
### moveToPrevious<sup>8+</sup> ###
### moveToPrevious<sup>8+</sup>
moveToPrevious(): boolean
......@@ -993,7 +993,7 @@ try {
```
### move<sup>8+</sup> ###
### move<sup>8+</sup>
move(offset: number): boolean
......@@ -1033,7 +1033,7 @@ try {
```
### moveToPosition<sup>8+</sup> ###
### moveToPosition<sup>8+</sup>
moveToPosition(position: number): boolean
......@@ -1073,7 +1073,7 @@ try {
```
### isFirst<sup>8+</sup> ###
### isFirst<sup>8+</sup>
isFirst(): boolean
......@@ -1107,7 +1107,7 @@ try {
```
### isLast<sup>8+</sup> ###
### isLast<sup>8+</sup>
isLast(): boolean
......@@ -1140,7 +1140,7 @@ try {
}
```
### isBeforeFirst<sup>8+</sup> ###
### isBeforeFirst<sup>8+</sup>
isBeforeFirst(): boolean
......@@ -1174,7 +1174,7 @@ try {
```
### isAfterLast<sup>8+</sup> ###
### isAfterLast<sup>8+</sup>
isAfterLast(): boolean
......@@ -1208,7 +1208,7 @@ try {
```
### getEntry<sup>8+</sup> ###
### getEntry<sup>8+</sup>
getEntry(): Entry
......@@ -1248,7 +1248,7 @@ Provides methods to create a **Query** object, which defines different data quer
**System capability**: SystemCapability.DistributedDataManager.KVStore.Core
### constructor<sup>8+</sup> ###
### constructor<sup>8+</sup>
constructor()
......@@ -1257,7 +1257,7 @@ A constructor used to create a **Schema** instance.
**System capability**: SystemCapability.DistributedDataManager.KVStore.Core
### reset<sup>8+</sup> ###
### reset<sup>8+</sup>
reset(): Query
......@@ -1288,7 +1288,7 @@ try {
```
### equalTo<sup>8+</sup> ###
### equalTo<sup>8+</sup>
equalTo(field: string, value: number|string|boolean): Query
......@@ -1323,7 +1323,7 @@ try {
```
### notEqualTo<sup>8+</sup> ###
### notEqualTo<sup>8+</sup>
notEqualTo(field: string, value: number|string|boolean): Query
......@@ -1358,7 +1358,7 @@ try {
```
### greaterThan<sup>8+</sup> ###
### greaterThan<sup>8+</sup>
greaterThan(field: string, value: number|string|boolean): Query
......@@ -1393,7 +1393,7 @@ try {
```
### lessThan<sup>8+</sup> ###
### lessThan<sup>8+</sup>
lessThan(field: string, value: number|string): Query
......@@ -1428,7 +1428,7 @@ try {
```
### greaterThanOrEqualTo<sup>8+</sup> ###
### greaterThanOrEqualTo<sup>8+</sup>
greaterThanOrEqualTo(field: string, value: number|string): Query
......@@ -1463,7 +1463,7 @@ try {
```
### lessThanOrEqualTo<sup>8+</sup> ###
### lessThanOrEqualTo<sup>8+</sup>
lessThanOrEqualTo(field: string, value: number|string): Query
......@@ -1498,7 +1498,7 @@ try {
```
### isNull<sup>8+</sup> ###
### isNull<sup>8+</sup>
isNull(field: string): Query
......@@ -1532,7 +1532,7 @@ try {
```
### inNumber<sup>8+</sup> ###
### inNumber<sup>8+</sup>
inNumber(field: string, valueList: number[]): Query
......@@ -1568,7 +1568,7 @@ try {
```
### inString<sup>8+</sup> ###
### inString<sup>8+</sup>
inString(field: string, valueList: string[]): Query
......@@ -1603,7 +1603,7 @@ try {
```
### notInNumber<sup>8+</sup> ###
### notInNumber<sup>8+</sup>
notInNumber(field: string, valueList: number[]): Query
......@@ -1638,7 +1638,7 @@ try {
```
### notInString<sup>8+</sup> ###
### notInString<sup>8+</sup>
notInString(field: string, valueList: string[]): Query
......@@ -1673,7 +1673,7 @@ try {
```
### like<sup>8+</sup> ###
### like<sup>8+</sup>
like(field: string, value: string): Query
......@@ -1708,7 +1708,7 @@ try {
```
### unlike<sup>8+</sup> ###
### unlike<sup>8+</sup>
unlike(field: string, value: string): Query
......@@ -1743,7 +1743,7 @@ try {
```
### and<sup>8+</sup> ###
### and<sup>8+</sup>
and(): Query
......@@ -1773,7 +1773,7 @@ try {
```
### or<sup>8+</sup> ###
### or<sup>8+</sup>
or(): Query
......@@ -1803,7 +1803,7 @@ try {
```
### orderByAsc<sup>8+</sup> ###
### orderByAsc<sup>8+</sup>
orderByAsc(field: string): Query
......@@ -1838,7 +1838,7 @@ try {
```
### orderByDesc<sup>8+</sup> ###
### orderByDesc<sup>8+</sup>
orderByDesc(field: string): Query
......@@ -1873,7 +1873,7 @@ try {
```
### limit<sup>8+</sup> ###
### limit<sup>8+</sup>
limit(total: number, offset: number): Query
......@@ -1911,7 +1911,7 @@ try {
```
### isNotNull<sup>8+</sup> ###
### isNotNull<sup>8+</sup>
isNotNull(field: string): Query
......@@ -1945,7 +1945,7 @@ try {
```
### beginGroup<sup>8+</sup> ###
### beginGroup<sup>8+</sup>
beginGroup(): Query
......@@ -1975,7 +1975,7 @@ try {
```
### endGroup<sup>8+</sup> ###
### endGroup<sup>8+</sup>
endGroup(): Query
......@@ -2005,7 +2005,7 @@ try {
```
### prefixKey<sup>8+</sup> ###
### prefixKey<sup>8+</sup>
prefixKey(prefix: string): Query
......@@ -2040,7 +2040,7 @@ try {
```
### setSuggestIndex<sup>8+</sup> ###
### setSuggestIndex<sup>8+</sup>
setSuggestIndex(index: string): Query
......@@ -2075,7 +2075,7 @@ try {
```
### deviceId<sup>8+</sup> ###
### deviceId<sup>8+</sup>
deviceId(deviceId:string):Query
......@@ -2109,7 +2109,7 @@ try {
```
### getSqlLike<sup>8+</sup> ###
### getSqlLike<sup>8+</sup>
getSqlLike():string
......@@ -2303,7 +2303,9 @@ try {
delete(predicates: dataSharePredicates.DataSharePredicates, callback: AsyncCallback&lt;void&gt;)
Deletes KV pairs that meet the specified predicates. This API uses an asynchronous callback to return the result.
Deletes KV pairs that meet the specified conditions. This API uses an asynchronous callback to return the result.
**System API**: This is a system API.
**System capability**: SystemCapability.DistributedDataManager.KVStore.Core
......@@ -2337,7 +2339,9 @@ try {
delete(predicates: dataSharePredicates.DataSharePredicates): Promise&lt;void&gt;
Deletes KV pairs that meet the specified predicates. This API uses a promise to return the result.
Deletes KV pairs that meet the specified conditions. This API uses a promise to return the result.
**System API**: This is a system API.
**System capability**: SystemCapability.DistributedDataManager.KVStore.Core
......@@ -2352,7 +2356,7 @@ Deletes KV pairs that meet the specified predicates. This API uses a promise to
| Type | Description |
| ------ | ------- |
| Promise&lt;void&gt; |Promise used to return the result.|
| Promise&lt;void&gt; |Promise that returns no value.|
**Example**
......@@ -2379,11 +2383,224 @@ try {
```
### backup<sup>9+</sup>
backup(file:string, callback: AsyncCallback&lt;void&gt;):void
Backs up an RDB store. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.DistributedDataManager.KVStore.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ------------------------- | ---- | ------------------------------------------------------------ |
| file | string | Yes | Name of the database. The value cannot be empty or exceed [MAX_KEY_LENGTH](#constants).|
| callback | AsyncCallback&lt;void&gt; | Yes | Callback used to return the result. If the operation is successful, **err** is **undefined**. Otherwise, **err** is the error object. |
**Example**
```js
let kvStore;
let file = "BK001";
try {
kvStore.backup(file, (err, data) => {
if (err) {
console.info("backup err : " + err);
} else {
console.info("backup data : " + data);
}
});
} catch (e) {
console.log("An unexpected error occurred. Error : " + e);
}
```
### backup<sup>9+</sup>
backup(file:string): Promise&lt;void&gt;
Backs up an RDB store. This API uses a promise to return the result.
**System capability**: SystemCapability.DistributedDataManager.KVStore.Core
**Parameters**
| Name| Type| Mandatory| Description |
| ------ | -------- | ---- | ------------------------------------------------------------ |
| file | string | Yes | Name of the database. This parameter cannot be empty and its length cannot exceed [MAX_KEY_LENGTH](#constants).|
**Return value**
| Type | Description |
| ------------------- | ------------------------- |
| Promise&lt;void&gt; | Promise that returns no value.|
**Example**
```js
let kvStore;
let file = "BK001";
try {
kvStore.backup(file).then((data) => {
console.info("backup data : " + data);
}).catch((err) => {
console.info("backup err : " + err);
});
} catch (e) {
console.log("An unexpected error occurred. Error : " + e);
}
```
### restore<sup>9+</sup>
restore(file:string, callback: AsyncCallback&lt;void&gt;):void
Restores an RDB store from a database file. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.DistributedDataManager.KVStore.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ------------------------- | ---- | ------------------------------------------------------------ |
| file | string | Yes | Name of the database file. The value cannot be empty or exceed [MAX_KEY_LENGTH](#constants).|
| callback | AsyncCallback&lt;void&gt; | Yes | Callback used to return the result. If the operation is successful, **err** is **undefined**. Otherwise, **err** is an error object.|
**Example**
```js
let kvStore;
let file = "BK001";
try {
kvStore.restore(file, (err, data) => {
if (err) {
console.info("restore err : " + err);
} else {
console.info("restore data : " + data);
}
});
} catch (e) {
console.log("An unexpected error occurred. Error : " + e);
}
```
### restore<sup>9+</sup>
restore(file:string): Promise&lt;void&gt;
Restores an RDB store from a database file. This API uses a promise to return the result.
**System capability**: SystemCapability.DistributedDataManager.KVStore.Core
**Parameters**
| Name| Type| Mandatory| Description |
| ------ | -------- | ---- | ------------------------------------------------------------ |
| file | string | Yes | Name of the database file. The value cannot be empty or exceed [MAX_KEY_LENGTH](#constants).|
**Return value**
| Type | Description |
| ------------------- | ------------------------- |
| Promise&lt;void&gt; | Promise that returns no value.|
**Example**
```js
let kvStore;
let file = "BK001";
try {
kvStore.restore(file).then((data) => {
console.info("restore data : " + data);
}).catch((err) => {
console.info("restore err : " + err);
});
} catch (e) {
console.log("An unexpected error occurred. Error : " + e);
}
```
### deleteBackup<sup>9+</sup>
deleteBackup(files:Array&lt;string&gt;, callback: AsyncCallback&lt;Array&lt;[string, number]&gt;&gt;):void
Deletes a backup file. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.DistributedDataManager.KVStore.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | -------------------------------------------------- | ---- | ------------------------------------------------------------ |
| files | Array&lt;string&gt; | Yes | Name of the backup file to delete. The value cannot be empty or exceed [MAX_KEY_LENGTH](#constants). |
| callback | AsyncCallback&lt;Array&lt;[string, number]&gt;&gt; | Yes | Callback invoked to return the name of the backup file deleted and the operation result. |
**Example**
```js
let kvStore;
let files = ["BK001", "BK002"];
try {
kvStore.deleteBackup(files, (err, data) => {
if (err) {
console.info("deleteBackup err : " + err);
} else {
console.info("deleteBackup data : " + data);
}
});
} catch (e) {
console.log("An unexpected error occurred. Error : " + e);
}
```
### deleteBackup<sup>9+</sup>
deleteBackup(files:Array&lt;string&gt;): Promise&lt;Array&lt;[string, number]&gt;&gt;
Deletes a backup file. This API uses a promise to return the result.
**System capability**: SystemCapability.DistributedDataManager.KVStore.Core
**Parameters**
| Name| Type| Mandatory| Description |
| ------ | -------- | ---- | ------------------------------------------------------------ |
| files | Array&lt;string&gt; | Yes | Name of the backup file to delete. The value cannot be empty or exceed [MAX_KEY_LENGTH](#constants).|
**Return value**
| Type | Description |
| -------------------------------------------- | ----------------------------------------------- |
| Promise&lt;Array&lt;[string, number]&gt;&gt; | Promise used to return the name of the backup file deleted and the operation result.|
**Example**
```js
let kvStore;
let files = ["BK001", "BK002"];
try {
kvStore.deleteBackup(files).then((data) => {
console.info("deleteBackup data : " + data);
}).catch((err) => {
console.info("deleteBackup err : " + err);
})
} catch (e) {
console.log("An unexpected error occurred. Error : " + e);
}
```
### on('dataChange')
on(event: 'dataChange', type: SubscribeType, listener: Callback&lt;ChangeNotification&gt;): void
Subscribes to data change notifications of the specified type.
Subscribes to data changes of the specified type.
**System capability**: SystemCapability.DistributedDataManager.KVStore.Core
......@@ -2391,9 +2608,9 @@ Subscribes to data change notifications of the specified type.
| Name | Type| Mandatory | Description |
| ----- | ------ | ---- | ----------------------- |
| event |string | Yes |Event to subscribe to. The value is **dataChange**, which indicates data changes. |
| type |[SubscribeType](#subscribetype) | Yes |Type of data changes. |
| listener |Callback&lt;[ChangeNotification](#changenotification)&gt; | Yes |Callback used to return the data changes.|
| event |string | Yes |Event to subscribe to. The value is **dataChange**, which indicates a data change event. |
| type |[SubscribeType](#subscribetype) | Yes |Type of data change. |
| listener |Callback&lt;[ChangeNotification](#changenotification)&gt; | Yes |Callback used to return a data change event.|
**Example**
......@@ -2409,7 +2626,7 @@ kvStore.on('dataChange', distributedData.SubscribeType.SUBSCRIBE_TYPE_LOCAL, fun
on(event: 'syncComplete', syncCallback: Callback&lt;Array&lt;[string, number]&gt;&gt;): void
Subscribes to data synchronization complete events.
Subscribes to synchronization complete events.
**System capability**: SystemCapability.DistributedDataManager.KVStore.Core
......@@ -2417,8 +2634,8 @@ Subscribes to data synchronization complete events.
| Name | Type| Mandatory | Description |
| ----- | ------ | ---- | ----------------------- |
| event |string | Yes |Event to subscribe to. The value is **syncComplete**, which indicates completion of a data synchronization. |
| syncCallback |Callback&lt;Array&lt;[string, number]&gt;&gt; | Yes |Callback used to return the data synchronization result. |
| event |string | Yes |Event to subscribe to. The value is **syncComplete**, which indicates a synchronization complete event. |
| syncCallback |Callback&lt;Array&lt;[string, number]&gt;&gt; | Yes |Callback used to return a synchronization complete event. |
**Example**
......@@ -2433,7 +2650,7 @@ kvStore.on('syncComplete', function (data) {
off(event:'dataChange', listener?: Callback&lt;ChangeNotification&gt;): void
Unsubscribes from data change notifications.
Unsubscribes from data changes.
**System capability**: SystemCapability.DistributedDataManager.KVStore.Core
......@@ -2441,26 +2658,35 @@ Unsubscribes from data change notifications.
| Name | Type| Mandatory | Description |
| ----- | ------ | ---- | ----------------------- |
| event |string | Yes |Event to unsubscribe from. The value is **dataChange**, which indicates data changes. |
| listener |Callback&lt;[ChangeNotification](#changenotification)&gt; |No |Callback used to return the data changes.|
| event |string | Yes |Event to unsubscribe from. The value is **dataChange**, which indicates a data change event. |
| listener |Callback&lt;[ChangeNotification](#changenotification)&gt; |No |Callback used to return a data change event.|
**Example**
```js
let kvStore;
kvStore.on('dataChange', function (data) {
console.log("callback call data: " + data);
});
kvStore.off('dataChange', function (data) {
console.log("callback call data: " + data);
});
class KvstoreModel {
call(data) {
console.log("dataChange: " + data);
}
subscribeDataChange() {
if (kvStore != null) {
kvStore.on('dataChange', distributedData.SubscribeType.SUBSCRIBE_TYPE_REMOTE, this.call);
}
}
unsubscribeDataChange() {
if (kvStore != null) {
kvStore.off('dataChange', this.call);
}
}
}
```
### off('syncComplete')<sup>9+</sup>
off(event: 'syncComplete', syncCallback?: Callback&lt;Array&lt;[string, number]&gt;&gt;): void
Unsubscribes from data change events. This API uses a synchronous callback to return the result.
Unsubscribes from data changes. This API returns the result synchronously.
**System capability**: SystemCapability.DistributedDataManager.KVStore.Core
......@@ -2468,21 +2694,27 @@ Unsubscribes from data change events. This API uses a synchronous callback to re
| Name | Type| Mandatory | Description |
| ----- | ------ | ---- | ----------------------- |
| event |string | Yes |Event to unsubscribe from. The value is **syncComplete**, which indicates completion of a data synchronization. |
| syncCallback |Callback&lt;Array&lt;[string, number]&gt;&gt; | No |Callback used to return the synchronization result. |
| event |string | Yes |Event to unsubscribe from. The value is **syncComplete**, which indicates a synchronization complete event. |
| syncCallback |Callback&lt;Array&lt;[string, number]&gt;&gt; | No |Callback used to return a synchronization complete event. |
**Example**
```js
let kvStore;
try {
const func = function (data) {
console.log('syncComplete ' + data)
};
kvStore.on('syncComplete', func);
kvStore.off('syncComplete', func);
}catch(e) {
console.log('syncComplete e ' + e);
class KvstoreModel {
call(data) {
console.log("syncComplete: " + data);
}
subscribeSyncComplete() {
if (kvStore != null) {
kvStore.on('syncComplete', this.call);
}
}
unsubscribeSyncComplete() {
if (kvStore != null) {
kvStore.off('syncComplete', this.call);
}
}
}
```
......@@ -2594,6 +2826,8 @@ putBatch(value: Array&lt;ValuesBucket&gt;, callback: AsyncCallback&lt;void&gt;):
Writes data to this KV store. This API uses an asynchronous callback to return the result.
**System API**: This is a system API.
**System capability**: SystemCapability.DistributedDataManager.KVStore.Core
**Parameters**
......@@ -2631,7 +2865,9 @@ try {
putBatch(value: Array&lt;ValuesBucket&gt;): Promise&lt;void&gt;
Writes data of the **valuesbucket** type to this KV store. This API uses a promise to return the result.
Write data to this KV store. This API uses a promise to return the result.
**System API**: This is a system API.
**System capability**: SystemCapability.DistributedDataManager.KVStore.Core
......@@ -2645,7 +2881,7 @@ Writes data of the **valuesbucket** type to this KV store. This API uses a promi
| Type | Description |
| ------ | ------- |
| Promise&lt;void&gt; |Promise used to return the result.|
| Promise&lt;void&gt; |Promise that returns no value.|
**Example**
......@@ -2719,7 +2955,7 @@ try {
```
### deleteBatch<sup>8+</sup> ###
### deleteBatch<sup>8+</sup>
deleteBatch(keys: string[]): Promise&lt;void&gt;
......@@ -2775,7 +3011,7 @@ try {
```
### startTransaction<sup>8+</sup> ###
### startTransaction<sup>8+</sup>
startTransaction(callback: AsyncCallback&lt;void&gt;): void
......@@ -2827,7 +3063,7 @@ try {
```
### startTransaction<sup>8+</sup> ###
### startTransaction<sup>8+</sup>
startTransaction(): Promise&lt;void&gt;
......@@ -2862,7 +3098,7 @@ try {
```
### commit<sup>8+</sup> ###
### commit<sup>8+</sup>
commit(callback: AsyncCallback&lt;void&gt;): void
......@@ -2894,7 +3130,7 @@ try {
```
### commit<sup>8+</sup> ###
### commit<sup>8+</sup>
commit(): Promise&lt;void&gt;
......@@ -2924,7 +3160,7 @@ try {
```
### rollback<sup>8+</sup> ###
### rollback<sup>8+</sup>
rollback(callback: AsyncCallback&lt;void&gt;): void
......@@ -2956,7 +3192,7 @@ try {
```
### rollback<sup>8+</sup> ###
### rollback<sup>8+</sup>
rollback(): Promise&lt;void&gt;
......@@ -2986,7 +3222,7 @@ try {
```
### enableSync<sup>8+</sup> ###
### enableSync<sup>8+</sup>
enableSync(enabled: boolean, callback: AsyncCallback&lt;void&gt;): void
......@@ -3019,7 +3255,7 @@ try {
```
### enableSync<sup>8+</sup> ###
### enableSync<sup>8+</sup>
enableSync(enabled: boolean): Promise&lt;void&gt;
......@@ -3055,7 +3291,7 @@ try {
```
### setSyncRange<sup>8+</sup> ###
### setSyncRange<sup>8+</sup>
setSyncRange(localLabels: string[], remoteSupportLabels: string[], callback: AsyncCallback&lt;void&gt;): void
......@@ -3087,7 +3323,7 @@ try {
```
### setSyncRange<sup>8+</sup> ###
### setSyncRange<sup>8+</sup>
setSyncRange(localLabels: string[], remoteSupportLabels: string[]): Promise&lt;void&gt;
......@@ -3279,7 +3515,7 @@ try {
}
```
### getEntries<sup>8+</sup> ###
### getEntries<sup>8+</sup>
getEntries(keyPrefix: string, callback: AsyncCallback&lt;Entry[]&gt;): void
......@@ -3325,7 +3561,7 @@ try {
```
### getEntries<sup>8+</sup> ###
### getEntries<sup>8+</sup>
getEntries(keyPrefix: string): Promise&lt;Entry[]&gt;
......@@ -3383,7 +3619,7 @@ try {
```
### getEntries<sup>8+</sup> ###
### getEntries<sup>8+</sup>
getEntries(query: Query, callback: AsyncCallback&lt;Entry[]&gt;): void
......@@ -3434,7 +3670,7 @@ try {
```
### getEntries<sup>8+</sup> ###
### getEntries<sup>8+</sup>
getEntries(query: Query): Promise&lt;Entry[]&gt;
......@@ -3492,7 +3728,7 @@ try {
```
### getResultSet<sup>8+</sup><a name="singlekvstore_getresultset"></a> ###
### getResultSet<sup>8+</sup><a name="singlekvstore_getresultset"></a>
getResultSet(keyPrefix: string, callback: AsyncCallback&lt;KvStoreResultSet&gt;): void
......@@ -3541,7 +3777,7 @@ try {
```
### getResultSet<sup>8+</sup> ###
### getResultSet<sup>8+</sup>
getResultSet(keyPrefix: string): Promise&lt;KvStoreResultSet&gt;
......@@ -3601,7 +3837,7 @@ try {
```
### getResultSet<sup>8+</sup> ###
### getResultSet<sup>8+</sup>
getResultSet(query: Query, callback: AsyncCallback&lt;KvStoreResultSet&gt;): void
......@@ -3649,7 +3885,7 @@ try {
```
### getResultSet<sup>8+</sup> ###
### getResultSet<sup>8+</sup>
getResultSet(query: Query): Promise&lt;KvStoreResultSet&gt;
......@@ -3705,12 +3941,14 @@ try {
}
```
### getResultSet<sup>9+</sup> ###
### getResultSet<sup>9+</sup>
getResultSet(predicates: dataSharePredicates.DataSharePredicates, callback: AsyncCallback&lt;KvStoreResultSet&gt;): void
Obtains a **KvStoreResultSet** object that matches the specified **DataSharePredicates** object. This API uses an asynchronous callback to return the result.
**System API**: This is a system API.
**System capability**: SystemCapability.DistributedDataManager.KVStore.Core
**Parameters**
......@@ -3740,12 +3978,14 @@ try {
console.log('An unexpected error occurred. Error:' + e);
}
```
### getResultSet<sup>9+</sup> ###
### getResultSet<sup>9+</sup>
getResultSet(predicates: dataSharePredicates.DataSharePredicates): Promise&lt;KvStoreResultSet&gt;
Obtains a **KvStoreResultSet** object that matches the specified **DataSharePredicates** object. This API uses a promise to return the result.
**System API**: This is a system API.
**System capability**: SystemCapability.DistributedDataManager.KVStore.Core
**Parameters**
......@@ -3758,7 +3998,7 @@ Obtains a **KvStoreResultSet** object that matches the specified **DataSharePred
| Type | Description |
| ------ | ------- |
|Promise&lt;[KvStoreResultSet](#kvstoreresultset8)&gt; |Promise used to return the **KvStoreResultSet** object obtained.|
|Promise&lt;[KvStoreResultSet](#kvstoreresultset8)&gt; |Promise that returns no value.|
**Example**
......@@ -3780,7 +4020,7 @@ try {
console.log('An unexpected error occurred. Error:' + e);
}
```
### closeResultSet<sup>8+</sup> ###
### closeResultSet<sup>8+</sup>
closeResultSet(resultSet: KvStoreResultSet, callback: AsyncCallback&lt;void&gt;): void
......@@ -3814,7 +4054,7 @@ try {
```
### closeResultSet<sup>8+</sup> ###
### closeResultSet<sup>8+</sup>
closeResultSet(resultSet: KvStoreResultSet): Promise&lt;void&gt;
......@@ -3851,7 +4091,7 @@ try {
```
### getResultSize<sup>8+</sup> ###
### getResultSize<sup>8+</sup>
getResultSize(query: Query, callback: AsyncCallback&lt;number&gt;): void
......@@ -3897,7 +4137,7 @@ try {
```
### getResultSize<sup>8+</sup> ###
### getResultSize<sup>8+</sup>
getResultSize(query: Query): Promise&lt;number&gt;
......@@ -3952,7 +4192,7 @@ try {
```
### removeDeviceData<sup>8+</sup> ###
### removeDeviceData<sup>8+</sup>
removeDeviceData(deviceId: string, callback: AsyncCallback&lt;void&gt;): void
......@@ -3994,7 +4234,7 @@ try {
```
### removeDeviceData<sup>8+</sup> ###
### removeDeviceData<sup>8+</sup>
removeDeviceData(deviceId: string): Promise&lt;void&gt;
......@@ -4043,11 +4283,11 @@ try {
```
### on('syncComplete')<sup>8+</sup> ###
### on('syncComplete')<sup>8+</sup>
on(event: 'syncComplete', syncCallback: Callback&lt;Array&lt;[string, number]&gt;&gt;): void
Subscribes to the data synchronization complete events.
Subscribes to synchronization complete events.
**System capability**: SystemCapability.DistributedDataManager.KVStore.Core
......@@ -4055,8 +4295,8 @@ Subscribes to the data synchronization complete events.
| Name | Type| Mandatory | Description |
| ----- | ------ | ---- | ----------------------- |
| event |string | Yes |Event to subscribe to. The value is **syncComplete**, which indicates completion of a data synchronization. |
| syncCallback |Callback&lt;Array&lt;[string, number]&gt;&gt; | Yes |Callback called to return the synchronization result. |
| event |string | Yes |Event to subscribe to. The value is **syncComplete**, which indicates a synchronization complete event. |
| syncCallback |Callback&lt;Array&lt;[string, number]&gt;&gt; | Yes |Callback invoked to return a synchronization complete event. |
**Example**
......@@ -4079,11 +4319,11 @@ try {
```
### off('syncComplete')<sup>8+</sup> ###
### off('syncComplete')<sup>8+</sup>
off(event: 'syncComplete', syncCallback?: Callback&lt;Array&lt;[string, number]&gt;&gt;): void
Unsubscribes from the data synchronization complete events.
Unsubscribes from synchronization complete events.
**System capability**: SystemCapability.DistributedDataManager.KVStore.Core
......@@ -4091,25 +4331,31 @@ Unsubscribes from the data synchronization complete events.
| Name | Type| Mandatory | Description |
| ----- | ------ | ---- | ----------------------- |
| event |string | Yes |Event to unsubscribe from. The value is **syncComplete**, which indicates completion of a data synchronization. |
| syncCallback |Callback&lt;Array&lt;[string, number]&gt;&gt; | No |Callback used to return the synchronization result. |
| event |string | Yes |Event to unsubscribe from. The value is **syncComplete**, which indicates a synchronization complete event. |
| syncCallback |Callback&lt;Array&lt;[string, number]&gt;&gt; | No |Callback used to return a synchronization complete event. |
**Example**
```js
let kvStore;
try {
const func = function (data) {
console.log('syncComplete ' + data)
};
kvStore.on('syncComplete', func);
kvStore.off('syncComplete', func);
}catch(e) {
console.log('syncComplete e ' + e);
class KvstoreModel {
call(data) {
console.log("syncComplete: " + data);
}
subscribeSyncComplete() {
if (kvStore != null) {
kvStore.on('syncComplete', this.call);
}
}
unsubscribeSyncComplete() {
if (kvStore != null) {
kvStore.off('syncComplete', this.call);
}
}
}
```
### on('dataChange')<sup>9+</sup> ###
### on('dataChange')<sup>9+</sup>
on(event: 'dataChange', type: SubscribeType, listener: Callback&lt;ChangeNotification&gt;): void
......@@ -4121,9 +4367,9 @@ Subscribes to data changes of the specified type. This API returns the result sy
| Name | Type| Mandatory | Description |
| ----- | ------ | ---- | ----------------------- |
| event |string | Yes |Event to subscribe to. The value is **dataChange**, which indicates data changes. |
| type |[SubscribeType](#subscribetype) | Yes |Subscription type. |
| listener |Callback&lt;[ChangeNotification](#changenotification)&gt; | Yes |Callback used to return the result.|
| event |string | Yes |Event to subscribe to. The value is **dataChange**, which indicates a data change event. |
| type |[SubscribeType](#subscribetype) | Yes |Type of data change. |
| listener |Callback&lt;[ChangeNotification](#changenotification)&gt; | Yes |Callback invoked to return a data change event.|
**Example**
......@@ -4135,11 +4381,11 @@ kvStore.on('dataChange', distributedData.SubscribeType.SUBSCRIBE_TYPE_LOCAL, fun
```
### off('dataChange')<sup>9+</sup> ###
### off('dataChange')<sup>9+</sup>
off(event:'dataChange', listener?: Callback&lt;ChangeNotification&gt;): void
Unsubscribes from the data change events. This API returns the result synchronously.
Unsubscribes from data changes. This API returns the result synchronously.
**System capability**: SystemCapability.DistributedDataManager.KVStore.Core
......@@ -4147,19 +4393,28 @@ Unsubscribes from the data change events. This API returns the result synchronou
| Name | Type| Mandatory | Description |
| ----- | ------ | ---- | ----------------------- |
| event |string | Yes |Event to unsubscribe from. The value is **dataChange**, which indicates data changes. |
| listener |Callback&lt;[ChangeNotification](#changenotification)&gt; |No |Callback used to return the result.|
| event |string | Yes |Event to unsubscribe from. The value is **dataChange**, which indicates a data change event. |
| listener |Callback&lt;[ChangeNotification](#changenotification)&gt; |No |Callback used to return a data change event.|
**Example**
```js
let kvStore;
kvStore.on('dataChange', function (data) {
console.log("callback call data: " + data);
});
kvStore.off('dataChange', function (data) {
console.log("callback call data: " + data);
});
class KvstoreModel {
call(data) {
console.log("dataChange: " + data);
}
subscribeDataChange() {
if (kvStore != null) {
kvStore.on('dataChange', distributedData.SubscribeType.SUBSCRIBE_TYPE_REMOTE, this.call);
}
}
unsubscribeDataChange() {
if (kvStore != null) {
kvStore.off('dataChange', this.call);
}
}
}
```
### sync<sup>7+</sup>
......@@ -4229,7 +4484,7 @@ try {
}
```
### setSyncParam<sup>8+</sup> ###
### setSyncParam<sup>8+</sup>
setSyncParam(defaultAllowedDelayMs: number, callback: AsyncCallback&lt;void&gt;): void
......@@ -4259,7 +4514,7 @@ try {
```
### setSyncParam<sup>8+</sup> ###
### setSyncParam<sup>8+</sup>
setSyncParam(defaultAllowedDelayMs: number): Promise&lt;void&gt;
......@@ -4297,7 +4552,7 @@ try {
```
### getSecurityLevel<sup>8+</sup> ###
### getSecurityLevel<sup>8+</sup>
getSecurityLevel(callback: AsyncCallback&lt;SecurityLevel&gt;): void
......@@ -4325,7 +4580,7 @@ try {
```
### getSecurityLevel<sup>8+</sup> ###
### getSecurityLevel<sup>8+</sup>
getSecurityLevel(): Promise&lt;SecurityLevel&gt;
......@@ -4365,7 +4620,7 @@ For example, a device KV store can be used to implement image sharing between de
Before calling any method in **DeviceKVStore**, you must use [getKVStore](#getkvstore) to obtain a **DeviceKVStore** object.
### get<sup>8+</sup> ###
### get<sup>8+</sup>
get(deviceId: string, key: string, callback: AsyncCallback&lt;boolean|string|number|Uint8Array&gt;): void
......@@ -4400,7 +4655,7 @@ try{
```
### get<sup>8+</sup> ###
### get<sup>8+</sup>
get(deviceId: string, key: string): Promise&lt;boolean|string|number|Uint8Array&gt;
......@@ -4444,7 +4699,7 @@ try {
```
### getEntries<sup>8+</sup> ###
### getEntries<sup>8+</sup>
getEntries(deviceId: string, keyPrefix: string, callback: AsyncCallback&lt;Entry[]&gt;): void
......@@ -4492,7 +4747,7 @@ try {
```
### getEntries<sup>8+</sup> ###
### getEntries<sup>8+</sup>
getEntries(deviceId: string, keyPrefix: string): Promise&lt;Entry[]&gt;
......@@ -4551,7 +4806,7 @@ try {
```
### getEntries<sup>8+</sup> ###
### getEntries<sup>8+</sup>
getEntries(query: Query, callback: AsyncCallback&lt;Entry[]&gt;): void
......@@ -4603,7 +4858,7 @@ try {
```
### getEntries<sup>8+</sup> ###
### getEntries<sup>8+</sup>
getEntries(query: Query): Promise&lt;Entry[]&gt;
......@@ -4661,7 +4916,7 @@ try {
```
### getEntries<sup>8+</sup> ###
### getEntries<sup>8+</sup>
getEntries(deviceId: string, query: Query, callback: AsyncCallback&lt;Entry[]&gt;): void
......@@ -4714,7 +4969,7 @@ try {
```
### getEntries<sup>8+</sup> ###
### getEntries<sup>8+</sup>
getEntries(deviceId: string, query: Query): Promise&lt;Entry[]&gt;
......@@ -4774,7 +5029,7 @@ try {
```
### getResultSet<sup>8+</sup><a name="devicekvstore_getresultset"></a> ###
### getResultSet<sup>8+</sup><a name="devicekvstore_getresultset"></a>
getResultSet(deviceId: string, keyPrefix: string, callback: AsyncCallback&lt;KvStoreResultSet&gt;): void
......@@ -4809,7 +5064,7 @@ try {
```
### getResultSet<sup>8+</sup> ###
### getResultSet<sup>8+</sup>
getResultSet(deviceId: string, keyPrefix: string): Promise&lt;KvStoreResultSet&gt;
......@@ -4853,7 +5108,7 @@ try {
```
### getResultSet<sup>8+</sup> ###
### getResultSet<sup>8+</sup>
getResultSet(query: Query, callback: AsyncCallback&lt;KvStoreResultSet&gt;): void
......@@ -4905,7 +5160,7 @@ try {
```
### getResultSet<sup>8+</sup> ###
### getResultSet<sup>8+</sup>
getResultSet(query: Query): Promise&lt;KvStoreResultSet&gt;
......@@ -4969,7 +5224,7 @@ try {
```
### getResultSet<sup>8+</sup> ###
### getResultSet<sup>8+</sup>
getResultSet(deviceId: string, query: Query, callback: AsyncCallback&lt;KvStoreResultSet&gt;): void
......@@ -5021,7 +5276,7 @@ try {
```
### getResultSet<sup>8+</sup> ###
### getResultSet<sup>8+</sup>
getResultSet(deviceId: string, query: Query): Promise&lt;KvStoreResultSet&gt;
......@@ -5087,7 +5342,7 @@ try {
```
### closeResultSet<sup>8+</sup> ###
### closeResultSet<sup>8+</sup>
closeResultSet(resultSet: KvStoreResultSet, callback: AsyncCallback&lt;void&gt;): void
......@@ -5122,7 +5377,7 @@ try {
```
### closeResultSet<sup>8+</sup> ###
### closeResultSet<sup>8+</sup>
closeResultSet(resultSet: KvStoreResultSet): Promise&lt;void&gt;
......@@ -5160,7 +5415,7 @@ try {
```
### getResultSize<sup>8+</sup> ###
### getResultSize<sup>8+</sup>
getResultSize(query: Query, callback: AsyncCallback&lt;number&gt;): void
......@@ -5207,7 +5462,7 @@ try {
```
### getResultSize<sup>8+</sup> ###
### getResultSize<sup>8+</sup>
getResultSize(query: Query): Promise&lt;number&gt;
......@@ -5263,7 +5518,7 @@ try {
```
### getResultSize<sup>8+</sup> ###
### getResultSize<sup>8+</sup>
getResultSize(deviceId: string, query: Query, callback: AsyncCallback&lt;number&gt;): void;
......@@ -5310,7 +5565,7 @@ try {
```
### getResultSize<sup>8+</sup> ###
### getResultSize<sup>8+</sup>
getResultSize(deviceId: string, query: Query): Promise&lt;number&gt;
......@@ -5366,7 +5621,7 @@ try {
```
### removeDeviceData<sup>8+</sup> ###
### removeDeviceData<sup>8+</sup>
removeDeviceData(deviceId: string, callback: AsyncCallback&lt;void&gt;): void
......@@ -5408,7 +5663,7 @@ try {
```
### removeDeviceData<sup>8+</sup> ###
### removeDeviceData<sup>8+</sup>
removeDeviceData(deviceId: string): Promise&lt;void&gt;
......@@ -5457,7 +5712,7 @@ try {
```
### sync<sup>8+</sup> ###
### sync<sup>8+</sup>
sync(deviceIds: string[], mode: SyncMode, delayMs?: number): void
......@@ -5496,7 +5751,7 @@ try {
}
```
### sync<sup>9+</sup> ###
### sync<sup>9+</sup>
sync(deviceIds: string[], query: Query, mode: SyncMode, delayMs?: number): void
......@@ -5538,11 +5793,11 @@ try {
}
```
### on('syncComplete')<sup>8+</sup> ###
### on('syncComplete')<sup>8+</sup>
on(event: 'syncComplete', syncCallback: Callback&lt;Array&lt;[string, number]&gt;&gt;): void
Subscribes to the data synchronization complete events.
Subscribes to synchronization complete events.
**System capability**: SystemCapability.DistributedDataManager.KVStore.Core
......@@ -5550,8 +5805,8 @@ Subscribes to the data synchronization complete events.
| Name | Type| Mandatory | Description |
| ----- | ------ | ---- | ----------------------- |
| event |string | Yes |Event to subscribe to. The value is **syncComplete**, which indicates the data synchronization complete event.|
| syncCallback |Callback<Array&lt;[string, number]&gt;> | Yes |Callback used to return the synchronization result. |
| event |string | Yes |Event to subscribe to. The value is **syncComplete**, which indicates a synchronization complete event.|
| syncCallback |Callback<Array&lt;[string, number]&gt;> | Yes |Callback invoked to return a synchronization complete event. |
**Example**
......@@ -5574,11 +5829,11 @@ try {
```
### off('syncComplete')<sup>8+</sup> ###
### off('syncComplete')<sup>8+</sup>
off(event: 'syncComplete', syncCallback?: Callback&lt;Array&lt;[string, number]&gt;&gt;): void
Unsubscribes from the synchronization complete events. This API returns the result synchronously.
Unsubscribes from synchronization complete events. This API returns the result synchronously.
**System capability**: SystemCapability.DistributedDataManager.KVStore.Core
......@@ -5586,25 +5841,31 @@ Unsubscribes from the synchronization complete events. This API returns the resu
| Name | Type| Mandatory | Description |
| ----- | ------ | ---- | ----------------------- |
| event |string | Yes |Event to unsubscribe from. The value is **syncComplete**, which indicates the data synchronization complete event.|
| syncCallback |Callback<Array&lt;[string, number]&gt;&gt; | No |Callback used to return the synchronization result. |
| event |string | Yes |Event to unsubscribe from. The value is **syncComplete**, which indicates a synchronization complete event.|
| syncCallback |Callback<Array&lt;[string, number]&gt;&gt; | No |Callback used to return a synchronization complete event. |
**Example**
```js
let kvStore;
try {
const func = function (data) {
console.log('syncComplete ' + data)
};
kvStore.on('syncComplete', func);
kvStore.off('syncComplete', func);
}catch(e) {
console.log('syncComplete e ' + e);
class KvstoreModel {
call(data) {
console.log("syncComplete: " + data);
}
subscribeSyncComplete() {
if (kvStore != null) {
kvStore.on('syncComplete', this.call);
}
}
unsubscribeSyncComplete() {
if (kvStore != null) {
kvStore.off('syncComplete', this.call);
}
}
}
```
### on('dataChange')<sup>9+</sup> ###
### on('dataChange')<sup>9+</sup>
on(event: 'dataChange', type: SubscribeType, listener: Callback&lt;ChangeNotification&gt;): void
......@@ -5616,9 +5877,9 @@ Subscribes to data changes of the specified type. This API returns the result sy
| Name | Type| Mandatory | Description |
| ----- | ------ | ---- | ----------------------- |
| event |string | Yes |Event to subscribe to. The value is **dataChange**, which indicates data changes. |
| type |[SubscribeType](#subscribetype) | Yes |Subscription type. |
| listener |Callback&lt;[ChangeNotification](#changenotification)&gt; | Yes |Callback used to return the result.|
| event |string | Yes |Event to subscribe to. The value is **dataChange**, which indicates a data change event. |
| type |[SubscribeType](#subscribetype) | Yes |Type of data change. |
| listener |Callback&lt;[ChangeNotification](#changenotification)&gt; | Yes |Callback invoked to return a data change event.|
**Example**
......@@ -5630,11 +5891,11 @@ kvStore.on('dataChange', distributedData.SubscribeType.SUBSCRIBE_TYPE_LOCAL, fun
```
### off('dataChange')<sup>9+</sup> ###
### off('dataChange')<sup>9+</sup>
off(event:'dataChange', listener?: Callback&lt;ChangeNotification&gt;): void
Unsubscribes from the data change events. This API returns the result synchronously.
Unsubscribes from data changes. This API returns the result synchronously.
**System capability**: SystemCapability.DistributedDataManager.KVStore.Core
......@@ -5642,19 +5903,28 @@ Unsubscribes from the data change events. This API returns the result synchronou
| Name | Type| Mandatory | Description |
| ----- | ------ | ---- | ----------------------- |
| event |string | Yes |Event to unsubscribe from. The value is **dataChange**, which indicates data changes. |
| listener |Callback&lt;[ChangeNotification](#changenotification)&gt; |No |Callback used to return the result.|
| event |string | Yes |Event to unsubscribe from. The value is **dataChange**, which indicates a data change event. |
| listener |Callback&lt;[ChangeNotification](#changenotification)&gt; |No |Callback used to return a data change event.|
**Example**
```js
let kvStore;
kvStore.on('dataChange', function (data) {
console.log("callback call data: " + data);
});
kvStore.off('dataChange', function (data) {
console.log("callback call data: " + data);
});
class KvstoreModel {
call(data) {
console.log("dataChange: " + data);
}
subscribeDataChange() {
if (kvStore != null) {
kvStore.on('dataChange', distributedData.SubscribeType.SUBSCRIBE_TYPE_REMOTE, this.call);
}
}
unsubscribeDataChange() {
if (kvStore != null) {
kvStore.off('dataChange', this.call);
}
}
}
```
## SyncMode
......@@ -5668,4 +5938,3 @@ Enumerates the synchronization modes.
| PULL_ONLY |0 |Pull data from the peer end to the local end only.|
| PUSH_ONLY |1 |Push data from the local end to the peer end only.|
| PUSH_PULL |2 |Push data from the local end to the peer end and then pull data from the peer end to the local end.|
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册