未验证 提交 3a8d41c7 编写于 作者: O openharmony_ci 提交者: Gitee

!3553 开发指南示例代码标记语言:无需翻译

Merge pull request !3553 from 葛亚芳/master
......@@ -77,7 +77,7 @@ The following uses a single KV store as an example to describe the development p
1. Import the distributed database module.
```
```js
import distributedData from '@ohos.data.distributedData';
```
......@@ -88,7 +88,7 @@ The following uses a single KV store as an example to describe the development p
The sample code is as follows:
```
```js
let kvManager;
try {
const kvManagerConfig = {
......@@ -118,7 +118,7 @@ The following uses a single KV store as an example to describe the development p
The sample code is as follows:
```
```js
let kvStore;
try {
const options = {
......@@ -149,7 +149,7 @@ The following uses a single KV store as an example to describe the development p
The following is the sample code for subscribing to the data changes of a single KV store:
```
```js
kvStore.on('dataChange', distributedData.SubscribeType.SUBSCRIBE_TYPE_ALL, function (data) {
console.log("dataChange callback call data: " + JSON.stringify(data));
});
......@@ -162,7 +162,7 @@ The following uses a single KV store as an example to describe the development p
The following is the sample code for writing key-value pairs of the string type into the single KV store:
```
```js
const KEY_TEST_STRING_ELEMENT = 'key_test_string';
const VALUE_TEST_STRING_ELEMENT = 'value-test-string';
try {
......@@ -185,7 +185,7 @@ The following uses a single KV store as an example to describe the development p
The following is the sample code for querying data of the string type from the single KV store:
```
```js
const KEY_TEST_STRING_ELEMENT = 'key_test_string';
const VALUE_TEST_STRING_ELEMENT = 'value-test-string';
try {
......@@ -210,7 +210,7 @@ The following uses a single KV store as an example to describe the development p
The following is the sample code for data synchronization in a single KV store. **deviceIds** can be obtained by deviceManager by calling **getTrustedDeviceListSync\(\)**, and **1000** indicates that the maximum delay time is 1000 ms.
```
```js
import deviceManager from '@ohos.distributedHardware.deviceManager';
let devManager;
......@@ -231,5 +231,3 @@ The following uses a single KV store as an example to describe the development p
}
kvStore.sync(deviceIds, distributedData.SyncMode.PUSH_ONLY, 1000);
```
......@@ -74,7 +74,7 @@ Use the following APIs to delete a **Storage** instance or data file.
1. Import @ohos.data.storage and related modules to the development environment.
```
```js
import dataStorage from '@ohos.data.storage'
import featureAbility from '@ohos.ability.featureAbility' // Used to obtain the file storage path.
```
......@@ -82,7 +82,7 @@ Use the following APIs to delete a **Storage** instance or data file.
2. Create a **Storage** instance.
Read the specified file and load its data to the **Storage** instance for data operations.
```
```js
var context = featureAbility.getContext()
context.getFilesDir().then(() => {
console.info("======================>getFilesDirPromsie====================>");
......@@ -95,7 +95,7 @@ Use the following APIs to delete a **Storage** instance or data file.
Use the **put()** method of the **Storage** class to write data to the cached **Storage** instance.
```
```js
promise.then((storage) => {
let getPromise = storage.put('startup', 'auto') // Save data to the Storage instance.
getPromise.then(() => {
......@@ -112,7 +112,7 @@ Use the following APIs to delete a **Storage** instance or data file.
Use the **get()** method of the **Storage** class to read data.
```
```js
promise.then((storage) => {
let getPromise = storage.get('startup', 'default')
getPromise.then((value) => {
......@@ -128,7 +128,7 @@ Use the following APIs to delete a **Storage** instance or data file.
Use the **flush()** or **flushSync()** method to flush data in the **Storage** instance to its file.
```
```js
storage.flush();
```
......@@ -136,7 +136,7 @@ Use the following APIs to delete a **Storage** instance or data file.
Specify **StorageObserver** as the callback to subscribe to data changes for an application. When the value of the subscribed key is changed and the **flush()** method is executed, **StorageObserver** will be invoked. Unregister the **StorageObserver** when it is no longer required.
```
```js
promise.then((storage) => {
var observer = function (key) {
console.info("The key of " + key + " changed.")
......@@ -155,7 +155,7 @@ Use the following APIs to delete a **Storage** instance or data file.
Use the **deleteStorage** method to delete the **Storage** singleton of the specified file from the memory, and delete the specified file, its backup file, and damaged files. After the specified files are deleted, the application cannot use that instance to perform any data operation. Otherwise, data inconsistency will occur. The deleted data and files cannot be restored.
```
```js
let promise = dataStorage.deleteStorage(path + '/mystore')
promise.then(() => {
console.info("Deleted successfully.")
......
......@@ -196,7 +196,7 @@ You can obtain the distributed table name for a remote device based on the local
The sample code is as follows:
```
```js
import data_rdb from '@ohos.data.rdb'
const CREATE_TABLE_TEST = "CREATE TABLE IF NOT EXISTS test (" + "id INTEGER PRIMARY KEY AUTOINCREMENT, " + "name TEXT NOT NULL, " + "age INTEGER, " + "salary REAL, " + "blobType BLOB)";
......@@ -213,7 +213,7 @@ You can obtain the distributed table name for a remote device based on the local
The sample code is as follows:
```
```js
var u8 = new Uint8Array([1, 2, 3])
const valueBucket = {"name": "Tom", "age": 18, "salary": 100.5, "blobType": u8,}
let insertPromise = rdbStore.insert("test", valueBucket)
......@@ -226,7 +226,7 @@ You can obtain the distributed table name for a remote device based on the local
The sample code is as follows:
```
```js
let predicates = new data_rdb.RdbPredicates("test");
predicates.equalTo("name", "Tom")
let promisequery = rdbStore.query(predicates)
......@@ -247,7 +247,7 @@ You can obtain the distributed table name for a remote device based on the local
The sample code is as follows:
```
```js
let promise = rdbStore.setDistributedTables(["test"])
promise.then(() => {
console.info("setDistributedTables success.")
......@@ -263,7 +263,7 @@ You can obtain the distributed table name for a remote device based on the local
The sample code is as follows:
```
```js
let predicate = new data_rdb.RdbPredicates('test')
predicate.inDevices(['12345678abcde'])
let promise = rdbStore.sync(rdb.SyncMode.SYNC_MODE_PUSH, predicate)
......@@ -283,7 +283,7 @@ You can obtain the distributed table name for a remote device based on the local
The sample code is as follows:
```
```js
function storeObserver(devices) {
for (let i = 0; i < devices.length; i++) {
console.log('device=' + device[i] + ' data changed')
......@@ -302,7 +302,7 @@ You can obtain the distributed table name for a remote device based on the local
The sample code is as follows:
```
```js
let tableName = rdbStore.obtainDistributedTableName(deviceId, "test");
let resultSet = rdbStore.querySql("SELECT * FROM " + tableName)
```
......@@ -105,7 +105,7 @@ You can implement page redirection through the [page router](../ui/ui-js-buildin
In the files of the first page, bind the **onclick** method to the button so that clicking the button redirects the user to the second page. This operation needs to be completed in both .js and .visual files.
- In the **index.js** file:
```
```js
import router from '@ohos.router';
export default {
......@@ -128,7 +128,7 @@ You can implement page redirection through the [page router](../ui/ui-js-buildin
- In the **second.js** file:
```
```js
import router from '@ohos.router';
export default {
......
......@@ -29,7 +29,7 @@ OpenHarmony系统中的分布式数据服务模块为开发者提供下面几种
以单版本分布式数据库为例,说明开发步骤。
1. 导入模块。
```
```js
import distributedData from '@ohos.data.distributedData';
```
......@@ -38,7 +38,7 @@ OpenHarmony系统中的分布式数据服务模块为开发者提供下面几种
2. 创建分布式数据库管理器实例。
以下为创建分布式数据库管理器的代码示例:
```
```js
let kvManager;
try {
const kvManagerConfig = {
......@@ -66,7 +66,7 @@ OpenHarmony系统中的分布式数据服务模块为开发者提供下面几种
2. 创建分布式数据库,建议关闭自动同步功能(autoSync:false),需要同步时主动调用sync接口。
以下为创建分布式数据库的代码示例:
```
```js
let kvStore;
try {
const options = {
......@@ -95,7 +95,7 @@ OpenHarmony系统中的分布式数据服务模块为开发者提供下面几种
4. 订阅分布式数据变化。
以下为订阅单版本分布式数据库数据变化通知的代码示例:
```
```js
kvStore.on('dataChange', distributedData.SubscribeType.SUBSCRIBE_TYPE_ALL, function (data) {
console.log("dataChange callback call data: " + JSON.stringify(data));
});
......@@ -107,7 +107,7 @@ OpenHarmony系统中的分布式数据服务模块为开发者提供下面几种
以下为将字符串类型键值数据写入分布式数据库的代码示例:
```
```js
const KEY_TEST_STRING_ELEMENT = 'key_test_string';
const VALUE_TEST_STRING_ELEMENT = 'value-test-string';
try {
......@@ -128,7 +128,7 @@ OpenHarmony系统中的分布式数据服务模块为开发者提供下面几种
2. 从单版本分布式数据库中获取数据。
以下为从分布式数据库中查询字符串类型数据的代码示例:
```
```js
const KEY_TEST_STRING_ELEMENT = 'key_test_string';
const VALUE_TEST_STRING_ELEMENT = 'value-test-string';
try {
......@@ -151,7 +151,7 @@ OpenHarmony系统中的分布式数据服务模块为开发者提供下面几种
1.选择同一组网环境下的设备以及同步模式,进行数据同步。
以下为单版本分布式数据库进行数据同步的代码示例,其中deviceIds可由deviceManager调用getTrustedDeviceListSync()方法得到,1000表示最大延迟时间为1000ms:
```
```js
import deviceManager from '@ohos.distributedHardware.deviceManager';
let devManager;
......
......@@ -74,7 +74,7 @@
1. 准备工作,导入@ohos.data.storage以及相关的模块到开发环境。
```
```js
import dataStorage from '@ohos.data.storage'
import featureAbility from '@ohos.ability.featureAbility' // 用于获取文件存储路径
```
......@@ -82,7 +82,7 @@
2. 获取Storage实例。
读取指定文件,将数据加载到Storage实例,用于数据操作。
```
```js
var context = featureAbility.getContext()
context.getFilesDir().then(() => {
console.info("======================>getFilesDirPromsie====================>");
......@@ -95,7 +95,7 @@
使用Storage put方法保存数据到缓存的实例中。
```
```js
promise.then((storage) => {
let getPromise = storage.put('startup', 'auto') // 保存数据到缓存的storage示例中。
getPromise.then(() => {
......@@ -112,7 +112,7 @@
使用Storage get方法读取数据。
```
```js
promise.then((storage) => {
let getPromise = storage.get('startup', 'default')
getPromise.then((value) => {
......@@ -128,7 +128,7 @@
应用存入数据到Storage实例后,可以通过flush或者flushSync方法将Storage实例回写到文件中。
```
```js
storage.flush();
```
......@@ -136,7 +136,7 @@
应用订阅数据变化需要指定StorageObserver作为回调方法。订阅的key的值发生变更后,当执行flush方法时,StorageObserver被触发回调。不再需要StorageObserver时请注销。
```
```js
promise.then((storage) => {
var observer = function (key) {
console.info("The key of " + key + " changed.")
......@@ -155,7 +155,7 @@
使用deleteStorage方法从内存中移除指定文件对应的Storage单实例,并删除指定文件及其备份文件、损坏文件。删除指定文件时,应用不允许再使用该实例进行数据操作,否则会出现数据一致性问题。删除后,数据及文件将不可恢复。
```
```js
let promise = dataStorage.deleteStorage(path + '/mystore')
promise.then(() => {
console.info("Deleted successfully.")
......
......@@ -196,7 +196,7 @@
示例代码如下:
```
```js
import data_rdb from '@ohos.data.rdb'
const CREATE_TABLE_TEST = "CREATE TABLE IF NOT EXISTS test (" + "id INTEGER PRIMARY KEY AUTOINCREMENT, " + "name TEXT NOT NULL, " + "age INTEGER, " + "salary REAL, " + "blobType BLOB)";
......@@ -213,7 +213,7 @@
示例代码如下:
```
```js
var u8 = new Uint8Array([1, 2, 3])
const valueBucket = {"name": "Tom", "age": 18, "salary": 100.5, "blobType": u8,}
let insertPromise = rdbStore.insert("test", valueBucket)
......@@ -226,7 +226,7 @@
示例代码如下:
```
```js
let predicates = new data_rdb.RdbPredicates("test");
predicates.equalTo("name", "Tom")
let promisequery = rdbStore.query(predicates)
......@@ -247,7 +247,7 @@
示例代码如下:
```
```js
let promise = rdbStore.setDistributedTables(["test"])
promise.then(() => {
console.info("setDistributedTables success.")
......@@ -263,7 +263,7 @@
示例代码如下:
```
```js
let predicate = new data_rdb.RdbPredicates('test')
predicate.inDevices(['12345678abcde'])
let promise = rdbStore.sync(rdb.SyncMode.SYNC_MODE_PUSH, predicate)
......@@ -283,7 +283,7 @@
示例代码如下:
```
```js
function storeObserver(devices) {
for (let i = 0; i < devices.length; i++) {
console.log('device=' + device[i] + ' data changed')
......@@ -302,7 +302,7 @@
示例代码如下:
```
```js
let tableName = rdbStore.obtainDistributedTableName(deviceId, "test");
let resultSet = rdbStore.querySql("SELECT * FROM " + tableName)
```
......
......@@ -109,7 +109,7 @@ OpenHarmony低代码开发方式具有丰富的UI界面编辑功能,通过可
在第一个页面中,跳转按钮绑定onclick方法,点击按钮时跳转到第二页。需同时处理js文件及visual文件。
-**index.js**”示例如下:
```
```js
import router from '@ohos.router';
export default {
......@@ -132,7 +132,7 @@ OpenHarmony低代码开发方式具有丰富的UI界面编辑功能,通过可
-**second.js**”示例如下:
```
```js
import router from '@ohos.router';
export default {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册