js-apis-data-preferences.md 37.5 KB
Newer Older
A
Annie_wang 已提交
1
# @ohos.data.preferences (Preferences)
A
annie_wangli 已提交
2

A
Annie_wang 已提交
3 4 5
The **Preferences** module provides APIs for processing data in the form of key-value (KV) pairs and supports persistence of the KV pairs when required.

The key is of the string type, and the value can be a number, a string, a Boolean value, or an array of numbers, strings, or Boolean values.
A
annie_wangli 已提交
6 7


A
Annie_wang 已提交
8
> **NOTE**<br/>
A
Annie_wang 已提交
9
>
A
Annie_wang 已提交
10
> The initial APIs of this module are supported since API version 9. Newly added APIs will be marked with a superscript to indicate their earliest API version.
A
annie_wangli 已提交
11 12


A
Annie_wang 已提交
13
## Modules to Import
A
annie_wangli 已提交
14

A
Annie_wang 已提交
15
```js
A
Annie_wang 已提交
16
import data_preferences from '@ohos.data.preferences';
A
annie_wangli 已提交
17 18
```

A
Annie_wang 已提交
19
## Constants
A
annie_wangli 已提交
20

A
Annie_wang 已提交
21
**System capability**: SystemCapability.DistributedDataManager.Preferences.Core
A
annie_wangli 已提交
22

A
Annie_wang 已提交
23 24
| Name            | Type| Readable| Writable| Description                                   |
| ---------------- | -------- | ---- | ---- | --------------------------------------- |
A
Annie_wang 已提交
25 26
| MAX_KEY_LENGTH   | number   | Yes  | No  | Maximum length of a key. The key must be less than 80 bytes.    |
| MAX_VALUE_LENGTH | number   | Yes  | No  | Maximum length of a value. The value must be less than 8192 bytes.|
A
annie_wangli 已提交
27 28


A
annie_wangli 已提交
29
## data_preferences.getPreferences
A
annie_wangli 已提交
30 31 32

getPreferences(context: Context, name: string, callback: AsyncCallback&lt;Preferences&gt;): void

A
Annie_wang 已提交
33
Obtains a **Preferences** instance. This API uses an asynchronous callback to return the result.
A
annie_wangli 已提交
34

A
Annie_wang 已提交
35
**System capability**: SystemCapability.DistributedDataManager.Preferences.Core
A
annie_wangli 已提交
36

A
Annie_wang 已提交
37
**Parameters**
A
Annie_wang 已提交
38 39 40

| Name  | Type                                            | Mandatory| Description                                                        |
| -------- | ------------------------------------------------ | ---- | ------------------------------------------------------------ |
A
Annie_wang 已提交
41 42
| context  | Context            | Yes  | Application context.<br>For the application context of the FA model, see [Context](js-apis-Context.md).<br>For the application context of the stage model, see [Context](js-apis-ability-context.md).                                                |
| name     | string                                           | Yes  | Name of the **Preferences** instance.|
A
Annie_wang 已提交
43
| callback | AsyncCallback&lt;[Preferences](#preferences)&gt; | Yes  | Callback invoked to return the result. If the operation is successful, **err** is **undefined** and **object** is the **Preferences** instance obtained. Otherwise, **err** is an error code.|
A
annie_wangli 已提交
44

A
Annie_wang 已提交
45
**Example**
A
Annie_wang 已提交
46

A
Annie_wang 已提交
47 48
FA model:

A
Annie_wang 已提交
49
```js
A
Annie_wang 已提交
50 51 52 53
// Obtain the context.
import featureAbility from '@ohos.ability.featureAbility';
let context = featureAbility.getContext();
let preferences = null;
A
Annie_wang 已提交
54 55 56 57 58 59 60 61 62 63 64 65

try {
    data_preferences.getPreferences(context, 'mystore', function (err, val) {
        if (err) {
	        console.info("Failed to get the preferences. code =" + err.code + ", message =" + err.message);
	        return;
	    }
	    console.info("Got the preferences successfully.");
	})
} catch (err) {
    console.info("Failed to get the preferences. code =" + err.code + ", message =" + err.message);
}
A
Annie_wang 已提交
66
```
A
annie_wangli 已提交
67

A
Annie_wang 已提交
68 69 70 71 72 73 74 75 76 77 78 79 80
Stage model:

```ts
// Obtain the context.
import Ability from '@ohos.application.Ability';
let context = null;
class MainAbility extends Ability{
    onWindowStageCreate(windowStage){
        context = this.context;
    }
}

let preferences = null;
A
Annie_wang 已提交
81 82 83 84 85 86 87 88 89 90 91
try {
    data_preferences.getPreferences(context, 'mystore', function (err, val) {
	    if (err) {
	        console.info("Failed to get the preferences. code =" + err.code + ", message =" + err.message);
	        return;
	    }
	    console.info("Got the preferences successfully.");
	})
} catch (err) {
	console.info("Failed to get the preferences. code =" + err.code + ", message =" + err.message);
}
A
Annie_wang 已提交
92
```
A
annie_wangli 已提交
93

A
annie_wangli 已提交
94
## data_preferences.getPreferences
A
annie_wangli 已提交
95 96 97

getPreferences(context: Context, name: string): Promise&lt;Preferences&gt;

A
Annie_wang 已提交
98
Obtains a **Preferences** instance. This API uses a promise to return the result.
A
annie_wangli 已提交
99

A
Annie_wang 已提交
100
**System capability**: SystemCapability.DistributedDataManager.Preferences.Core
A
annie_wangli 已提交
101

A
Annie_wang 已提交
102
**Parameters**
A
Annie_wang 已提交
103 104 105 106

| Name | Type                                 | Mandatory| Description                   |
| ------- | ------------------------------------- | ---- | ----------------------- |
| context | Context | Yes  | Application context.<br>For the application context of the FA model, see [Context](js-apis-Context.md).<br>For the application context of the stage model, see [Context](js-apis-ability-context.md).           |
A
Annie_wang 已提交
107
| name    | string                                | Yes  | Name of the **Preferences** instance.|
A
annie_wangli 已提交
108

A
Annie_wang 已提交
109
**Return value**
A
Annie_wang 已提交
110

A
Annie_wang 已提交
111 112 113
| Type                                      | Description                              |
| ------------------------------------------ | ---------------------------------- |
| Promise&lt;[Preferences](#preferences)&gt; | Promise used to return the **Preferences** instance obtained.|
A
annie_wangli 已提交
114

A
Annie_wang 已提交
115
**Example**
A
Annie_wang 已提交
116

A
Annie_wang 已提交
117 118
FA model:

A
Annie_wang 已提交
119
```js
A
Annie_wang 已提交
120 121 122 123 124
// Obtain the context.
import featureAbility from '@ohos.ability.featureAbility';
let context = featureAbility.getContext();

let preferences = null;
A
Annie_wang 已提交
125 126 127 128 129 130 131 132 133 134 135
try {
    let promise = data_preferences.getPreferences(context, 'mystore');
    promise.then((object) => {
        preferences = object;
        console.info("Got the preferences successfully.");
    }).catch((err) => {
        console.log("Failed to get the preferences. code =" + err.code + ", message =" + err.message);
    })
} catch(err) {
    console.log("Failed to get the preferences. code =" + err.code + ", message =" + err.message);
}
A
Annie_wang 已提交
136
```
A
annie_wangli 已提交
137

A
Annie_wang 已提交
138 139 140 141 142 143 144 145 146 147 148 149 150
Stage model:

```ts
// Obtain the context.
import Ability from '@ohos.application.Ability';
let context = null;
class MainAbility extends Ability{
    onWindowStageCreate(windowStage){
        context = this.context;
    }
}

let preferences = null;
A
Annie_wang 已提交
151 152 153 154 155 156 157 158 159 160 161
try {
    let promise = data_preferences.getPreferences(context, 'mystore');
    promise.then((object) => {
        preferences = object;
        console.info("Got the preferences successfully.");
    }).catch((err) => {
        console.log("Failed to get the preferences. code =" + err.code + ", message =" + err.message);
    })
} catch(err) {
    console.log("Failed to get the preferences. code =" + err.code + ", message =" + err.message);
}
A
Annie_wang 已提交
162
```
A
annie_wangli 已提交
163

A
annie_wangli 已提交
164
## data_preferences.deletePreferences
A
annie_wangli 已提交
165 166 167

deletePreferences(context: Context, name: string, callback: AsyncCallback&lt;void&gt;): void

A
Annie_wang 已提交
168 169 170 171 172
Deletes a **Preferences** instance from the memory. This API uses an asynchronous callback to return the result.

If the **Preferences** instance has a persistent file, this API also deletes the persistent file.

The deleted **Preferences** instance cannot be used for data operations. Otherwise, data inconsistency will be caused.
A
annie_wangli 已提交
173

A
Annie_wang 已提交
174
**System capability**: SystemCapability.DistributedDataManager.Preferences.Core
A
annie_wangli 已提交
175

A
Annie_wang 已提交
176
**Parameters**
A
Annie_wang 已提交
177

A
Annie_wang 已提交
178 179
| Name  | Type                                 | Mandatory| Description                                                |
| -------- | ------------------------------------- | ---- | ---------------------------------------------------- |
A
Annie_wang 已提交
180
| context  | Context | Yes  | Application context.<br>For the application context of the FA model, see [Context](js-apis-Context.md).<br>For the application context of the stage model, see [Context](js-apis-ability-context.md).                                        |
A
Annie_wang 已提交
181 182
| name     | string                                | Yes  | Name of the **Preferences** instance to delete.                          |
| callback | AsyncCallback&lt;void&gt;             | Yes  | Callback invoked to return the result. If the operation is successful, **err** is **undefined**. Otherwise, **err** is an error code.|
A
annie_wangli 已提交
183

A
Annie_wang 已提交
184 185 186 187 188 189 190 191
**Error codes**

For details about the following error codes, see [Preference Error Codes](../errorcodes/errorcode-preferences.md).

| ID| Error Message                      |
| -------- | ------------------------------|
| 15500010 | Failed to delete the preferences. |

A
Annie_wang 已提交
192
**Example**
A
Annie_wang 已提交
193 194 195

FA model:

A
Annie_wang 已提交
196
```js
A
Annie_wang 已提交
197 198 199 200
// Obtain the context.
import featureAbility from '@ohos.ability.featureAbility';
let context = featureAbility.getContext();

A
Annie_wang 已提交
201 202 203 204 205 206 207 208 209 210 211
try {
    data_preferences.deletePreferences(context, 'mystore', function (err, val) {
        if (err) {
            console.info("Failed to delete the preferences. code =" + err.code + ", message =" + err.message);
            return;
        }
        console.info("Deleted the preferences successfully." );
    })
} catch (err) {
    console.info("Failed to delete the preferences. code =" + err.code + ", message =" + err.message);
}
A
Annie_wang 已提交
212
```
A
annie_wangli 已提交
213

A
Annie_wang 已提交
214 215 216 217 218 219 220 221 222 223 224 225
Stage model:

```ts
// Obtain the context.
import Ability from '@ohos.application.Ability';
let context = null;
class MainAbility extends Ability{
    onWindowStageCreate(windowStage){
        context = this.context;
    }
}

A
Annie_wang 已提交
226 227 228 229 230 231 232 233 234 235 236
try {
    data_preferences.deletePreferences(context, 'mystore', function (err, val) {
        if (err) {
            console.info("Failed to delete the preferences. code =" + err.code + ", message =" + err.message);
            return;
        }
        console.info("Deleted the preferences successfully." );
    })
} catch (err) {
    console.info("Failed to delete the preferences. code =" + err.code + ", message =" + err.message);
}
A
Annie_wang 已提交
237
```
A
annie_wangli 已提交
238

A
annie_wangli 已提交
239
## data_preferences.deletePreferences
A
annie_wangli 已提交
240 241 242

deletePreferences(context: Context, name: string): Promise&lt;void&gt;

A
Annie_wang 已提交
243 244 245 246 247
Deletes a **Preferences** instance from the memory. This API uses a promise to return the result.

If the **Preferences** instance has a persistent file, this API also deletes the persistent file.

The deleted **Preferences** instance cannot be used for data operations. Otherwise, data inconsistency will be caused.
A
annie_wangli 已提交
248

A
Annie_wang 已提交
249
**System capability**: SystemCapability.DistributedDataManager.Preferences.Core
A
annie_wangli 已提交
250

A
Annie_wang 已提交
251
**Parameters**
A
Annie_wang 已提交
252 253 254 255

| Name | Type                                 | Mandatory| Description                   |
| ------- | ------------------------------------- | ---- | ----------------------- |
| context | Context | Yes  | Application context.<br>For the application context of the FA model, see [Context](js-apis-Context.md).<br>For the application context of the stage model, see [Context](js-apis-ability-context.md).           |
A
Annie_wang 已提交
256
| name    | string                                | Yes  | Name of the **Preferences** instance to delete.|
A
annie_wangli 已提交
257

A
Annie_wang 已提交
258
**Return value**
A
Annie_wang 已提交
259

A
Annie_wang 已提交
260 261 262
| Type               | Description                     |
| ------------------- | ------------------------- |
| Promise&lt;void&gt; | Promise that returns no value.|
A
annie_wangli 已提交
263

A
Annie_wang 已提交
264 265 266 267 268 269 270 271
**Error codes**

For details about the following error codes, see [Preference Error Codes](../errorcodes/errorcode-preferences.md).

| ID| Error Message                      |
| -------- | ------------------------------|
| 15500010 | Failed to delete the preferences. |

A
Annie_wang 已提交
272
**Example**
A
Annie_wang 已提交
273 274 275

FA model:

A
Annie_wang 已提交
276
```js
A
Annie_wang 已提交
277 278 279 280
// Obtain the context.
import featureAbility from '@ohos.ability.featureAbility';
let context = featureAbility.getContext();

A
Annie_wang 已提交
281 282 283 284 285 286 287 288 289 290
try {
    let promise = data_preferences.deletePreferences(context, 'mystore');
    promise.then(() => {
        console.info("Deleted the preferences successfully.");
    }).catch((err) => {
        console.info("Failed to delete the preferences. code =" + err.code + ", message =" + err.message);
    })
} catch(err) {
    console.info("Failed to delete the preferences. code =" + err.code + ", message =" + err.message);
}
A
Annie_wang 已提交
291
```
A
annie_wangli 已提交
292

A
Annie_wang 已提交
293 294 295 296 297 298 299 300 301 302 303 304
Stage model:

```ts
// Obtain the context.
import Ability from '@ohos.application.Ability';
let context = null;
class MainAbility extends Ability{
    onWindowStageCreate(windowStage){
        context = this.context;
    }
}

A
Annie_wang 已提交
305 306 307 308 309 310 311 312 313 314
try{
    let promise = data_preferences.deletePreferences(context, 'mystore');
    promise.then(() => {
        console.info("Deleted the preferences successfully.");
    }).catch((err) => {
        console.info("Failed to delete the preferences. code =" + err.code + ", message =" + err.message);
    })
} catch(err) {
    console.info("Failed to delete the preferences. code =" + err.code + ", message =" + err.message);
}
A
Annie_wang 已提交
315
```
A
annie_wangli 已提交
316

A
annie_wangli 已提交
317
## data_preferences.removePreferencesFromCache
A
annie_wangli 已提交
318 319 320

removePreferencesFromCache(context: Context, name: string, callback: AsyncCallback&lt;void&gt;): void

A
Annie_wang 已提交
321
Removes a **Preferences** instance from the memory. This API uses an asynchronous callback to return the result.
A
annie_wangli 已提交
322

A
Annie_wang 已提交
323
The removed **Preferences** instance cannot be used for data operations. Otherwise, data inconsistency will be caused.
A
annie_wangli 已提交
324

A
Annie_wang 已提交
325
**System capability**: SystemCapability.DistributedDataManager.Preferences.Core
A
annie_wangli 已提交
326

A
Annie_wang 已提交
327
**Parameters**
A
Annie_wang 已提交
328

A
Annie_wang 已提交
329 330
| Name  | Type                                 | Mandatory| Description                                                |
| -------- | ------------------------------------- | ---- | ---------------------------------------------------- |
A
Annie_wang 已提交
331
| context  | Context | Yes  | Application context.<br>For the application context of the FA model, see [Context](js-apis-Context.md).<br>For the application context of the stage model, see [Context](js-apis-ability-context.md).                                        |
A
Annie_wang 已提交
332 333
| name     | string                                | Yes  | Name of the **Preferences** instance to remove.                          |
| callback | AsyncCallback&lt;void&gt;             | Yes  | Callback invoked to return the result. If the operation is successful, **err** is **undefined**. Otherwise, **err** is an error code.|
A
annie_wangli 已提交
334

A
Annie_wang 已提交
335
**Example**
A
Annie_wang 已提交
336 337 338

FA model:

A
Annie_wang 已提交
339
```js
A
Annie_wang 已提交
340 341 342 343
// Obtain the context.
import featureAbility from '@ohos.ability.featureAbility';
let context = featureAbility.getContext();

A
Annie_wang 已提交
344 345 346 347 348 349 350 351 352 353 354
try {
    data_preferences.removePreferencesFromCache(context, 'mystore', function (err, val) {
        if (err) {
            console.info("Failed to remove the preferences. code =" + err.code + ", message =" + err.message);
            return;
        }
        console.info("Removed the preferences successfully.");
    })
} catch (err) {
    console.info("Failed to remove the preferences. code =" + err.code + ", message =" + err.message);
}
A
Annie_wang 已提交
355
```
A
annie_wangli 已提交
356

A
Annie_wang 已提交
357 358 359 360 361 362 363 364 365 366 367 368
Stage model:

```ts
// Obtain the context.
import Ability from '@ohos.application.Ability';
let context = null;
class MainAbility extends Ability{
    onWindowStageCreate(windowStage){
        context = this.context;
    }
}

A
Annie_wang 已提交
369 370 371 372 373 374 375 376 377 378 379 380
try {
    data_preferences.removePreferencesFromCache(context, 'mystore', function (err, val) {
        if (err) {
            console.info("Failed to remove the preferences. code =" + err.code + ", message =" + err.message);
            return;
        }
        console.info("Removed the preferences successfully.");
    })
} catch (err) {
    console.info("Failed to remove the preferences. code =" + err.code + ", message =" + err.message);
}

A
Annie_wang 已提交
381
```
A
annie_wangli 已提交
382

A
annie_wangli 已提交
383
## data_preferences.removePreferencesFromCache
A
annie_wangli 已提交
384 385 386

removePreferencesFromCache(context: Context, name: string): Promise&lt;void&gt;

A
Annie_wang 已提交
387
Removes a **Preferences** instance from the memory. This API uses a promise to return the result.
A
annie_wangli 已提交
388

A
Annie_wang 已提交
389
The removed **Preferences** instance cannot be used for data operations. Otherwise, data inconsistency will be caused.
A
annie_wangli 已提交
390

A
Annie_wang 已提交
391
**System capability**: SystemCapability.DistributedDataManager.Preferences.Core
A
annie_wangli 已提交
392

A
Annie_wang 已提交
393
**Parameters**
A
Annie_wang 已提交
394 395 396 397

| Name | Type                                 | Mandatory| Description                   |
| ------- | ------------------------------------- | ---- | ----------------------- |
| context | Context | Yes  | Application context.<br>For the application context of the FA model, see [Context](js-apis-Context.md).<br>For the application context of the stage model, see [Context](js-apis-ability-context.md).           |
A
Annie_wang 已提交
398
| name    | string                                | Yes  | Name of the **Preferences** instance to remove.|
A
annie_wangli 已提交
399

A
Annie_wang 已提交
400
**Return value**
A
Annie_wang 已提交
401

A
Annie_wang 已提交
402 403 404
| Type               | Description                     |
| ------------------- | ------------------------- |
| Promise&lt;void&gt; | Promise that returns no value.|
A
annie_wangli 已提交
405

A
Annie_wang 已提交
406
**Example**
A
Annie_wang 已提交
407 408 409

FA model:

A
Annie_wang 已提交
410
```js
A
Annie_wang 已提交
411 412 413 414
// Obtain the context.
import featureAbility from '@ohos.ability.featureAbility';
let context = featureAbility.getContext();

A
Annie_wang 已提交
415 416 417 418 419 420 421 422 423 424
try {
    let promise = data_preferences.removePreferencesFromCache(context, 'mystore');
	promise.then(() => {
    	console.info("Removed the preferences successfully.");
    }).catch((err) => {
        console.info("Failed to remove the preferences. code =" + err.code + ", message =" + err.message);
    })
} catch(err) {
    console.info("Failed to remove the preferences. code =" + err.code + ", message =" + err.message);
}
A
Annie_wang 已提交
425
```
A
annie_wangli 已提交
426

A
Annie_wang 已提交
427 428 429 430 431 432 433 434 435 436 437 438
Stage model:

```ts
// Obtain the context.
import Ability from '@ohos.application.Ability';
let context = null;
class MainAbility extends Ability{
    onWindowStageCreate(windowStage){
        context = this.context;
    }
}

A
Annie_wang 已提交
439 440 441 442 443 444 445 446 447 448
try {
    let promise = data_preferences.removePreferencesFromCache(context, 'mystore');
	promise.then(() => {
    	console.info("Removed the preferences successfully.");
    }).catch((err) => {
        console.info("Failed to remove the preferences. code =" + err.code + ", message =" + err.message);
    })
} catch(err) {
    console.info("Failed to remove the preferences. code =" + err.code + ", message =" + err.message);
}
A
Annie_wang 已提交
449
```
A
annie_wangli 已提交
450 451 452

## Preferences

A
Annie_wang 已提交
453 454 455
Provides methods for obtaining and modifying data.

Before calling any method of **Preferences**, you must obtain a **Preferences** instance by using [data_preferences.getPreferences](#data_preferencesgetpreferences).
A
annie_wangli 已提交
456 457 458 459 460 461


### get

get(key: string, defValue: ValueType, callback: AsyncCallback&lt;ValueType&gt;): void

A
Annie_wang 已提交
462
Obtains the value of a key. This API uses an asynchronous callback to return the result. If the value is **null** or is not the type of the default value, the default value is returned.
A
annie_wangli 已提交
463

A
Annie_wang 已提交
464
**System capability**: SystemCapability.DistributedDataManager.Preferences.Core
A
annie_wangli 已提交
465

A
Annie_wang 已提交
466
**Parameters**
A
Annie_wang 已提交
467

A
Annie_wang 已提交
468 469 470 471 472
| Name  | Type                                        | Mandatory| Description                                                        |
| -------- | -------------------------------------------- | ---- | ------------------------------------------------------------ |
| key      | string                                       | Yes  | Key of the data to obtain. It cannot be empty.                             |
| defValue | [ValueType](#valuetype)                      | Yes  | Default value to be returned. The value can be a number, a string, a Boolean value, or an array of numbers, strings, or Boolean values.|
| callback | AsyncCallback&lt;[ValueType](#valuetype)&gt; | Yes  | Callback invoked to return the result. If the operation is successful, **err** is** undefined** and **data** is the value obtained. Otherwise, **err** is an error code.|
A
annie_wangli 已提交
473

A
Annie_wang 已提交
474
**Example**
A
Annie_wang 已提交
475 476

```js
A
Annie_wang 已提交
477 478 479 480 481 482 483 484 485 486 487
try {
    preferences.get('startup', 'default', function (err, val) {
        if (err) {
            console.info("Failed to get the value of 'startup'. code =" + err.code + ", message =" + err.message);
            return;
        }
        console.info("Obtained the value of 'startup' successfully. val: " + val);
    })
} catch (err) {
    console.info("Failed to get the value of 'startup'. code =" + err.code + ", message =" + err.message);
}
A
Annie_wang 已提交
488
```
A
annie_wangli 已提交
489 490 491 492 493 494


### get

get(key: string, defValue: ValueType): Promise&lt;ValueType&gt;

A
Annie_wang 已提交
495
Obtains the value of a key. This API uses a promise to return the result. If the value is **null** or is not the type of the default value, the default value is returned.
A
annie_wangli 已提交
496

A
Annie_wang 已提交
497
**System capability**: SystemCapability.DistributedDataManager.Preferences.Core
A
annie_wangli 已提交
498

A
Annie_wang 已提交
499
 **Parameters**
A
Annie_wang 已提交
500

A
Annie_wang 已提交
501 502 503 504
| Name  | Type                   | Mandatory| Description                                                        |
| -------- | ----------------------- | ---- | ------------------------------------------------------------ |
| key      | string                  | Yes  | Key of the data to obtain. It cannot be empty.                             |
| defValue | [ValueType](#valuetype) | Yes  | Default value to be returned. The value can be a number, a string, a Boolean value, or an array of numbers, strings, or Boolean values.|
A
annie_wangli 已提交
505

A
Annie_wang 已提交
506
**Return value**
A
Annie_wang 已提交
507 508 509 510

| Type                               | Description                         |
| ----------------------------------- | ----------------------------- |
| Promise<[ValueType](#valuetype)&gt; | Promise used to return the value obtained.|
A
annie_wangli 已提交
511

A
Annie_wang 已提交
512
**Example**
A
Annie_wang 已提交
513

A
Annie_wang 已提交
514
```js
A
Annie_wang 已提交
515 516 517 518 519 520 521 522 523 524
try {
    let promise = preferences.get('startup', 'default');
    promise.then((data) => {
        console.info("Got the value of 'startup'. Data: " + data);
    }).catch((err) => {
        console.info("Failed to get value of 'startup'. code =" + err.code + ", message =" + err.message);
    })
} catch(err) {
    console.info("Failed to get the value of 'startup'. code =" + err.code + ", message =" + err.message);
}
A
Annie_wang 已提交
525
```
A
annie_wangli 已提交
526

A
Annie_wang 已提交
527 528 529 530
### getAll

getAll(callback: AsyncCallback&lt;Object&gt;): void;

A
Annie_wang 已提交
531
Obtains an **Object** instance that contains all KV pairs. This API uses an asynchronous callback to return the result.
A
Annie_wang 已提交
532 533 534 535

**System capability**: SystemCapability.DistributedDataManager.Preferences.Core

**Parameters**
A
Annie_wang 已提交
536

A
Annie_wang 已提交
537 538 539
| Name  | Type                       | Mandatory| Description                                                        |
| -------- | --------------------------- | ---- | ------------------------------------------------------------ |
| callback | AsyncCallback&lt;Object&gt; | Yes  | Callback invoked to return the result. If the operation is successful, **err** is **undefined** and **value** is the **Object** instance obtained. Otherwise, **err** is an error code.|
A
Annie_wang 已提交
540 541

**Example**
A
Annie_wang 已提交
542 543

```js
A
Annie_wang 已提交
544 545 546 547 548 549
try {
    preferences.getAll(function (err, value) {
        if (err) {
            console.info("Failed to get all KV pairs. code =" + err.code + ", message =" + err.message);
            return;
        }
A
Annie_wang 已提交
550 551 552
    let allKeys = Object.keys(value);
    console.info("getAll keys = " + allKeys);
    console.info("getAll object = " + JSON.stringify(value));
A
Annie_wang 已提交
553 554 555 556
    })
} catch (err) {
    console.info("Failed to get all KV pairs. code =" + err.code + ", message =" + err.message);
}
A
Annie_wang 已提交
557 558 559 560 561 562 563
```


### getAll

getAll(): Promise&lt;Object&gt;

A
Annie_wang 已提交
564
Obtains an **Object** instance that contains all KV pairs. This API uses a promise to return the result.
A
Annie_wang 已提交
565 566 567 568

**System capability**: SystemCapability.DistributedDataManager.Preferences.Core

**Return value**
A
Annie_wang 已提交
569

A
Annie_wang 已提交
570 571 572
| Type                 | Description                                       |
| --------------------- | ------------------------------------------- |
| Promise&lt;Object&gt; | Promise used to return the **Object** instance obtained.|
A
Annie_wang 已提交
573 574

**Example**
A
Annie_wang 已提交
575

A
Annie_wang 已提交
576
```js
A
Annie_wang 已提交
577 578 579 580 581 582 583 584 585 586 587 588
try {
    let promise = preferences.getAll();
    promise.then((value) => {
        let allKeys = Object.keys(value);
        console.info('getAll keys = ' + allKeys);
        console.info("getAll object = " + JSON.stringify(value));
    }).catch((err) => {
        console.info("Failed to get all KV pairs. code =" + err.code + ", message =" + err.message);
    })
} catch (err) {
    console.info("Failed to get all KV pairs. code =" + err.code + ", message =" + err.message);
}
A
Annie_wang 已提交
589
```
A
annie_wangli 已提交
590 591 592 593 594

### put

put(key: string, value: ValueType, callback: AsyncCallback&lt;void&gt;): void

A
Annie_wang 已提交
595
Writes data to this **Preferences** instance. This API uses an asynchronous callback to return the result. You can use [flush](#flush) to make the **Preferences** instance persistent.
A
annie_wangli 已提交
596

A
Annie_wang 已提交
597
**System capability**: SystemCapability.DistributedDataManager.Preferences.Core
A
annie_wangli 已提交
598

A
Annie_wang 已提交
599
**Parameters**
A
Annie_wang 已提交
600

A
Annie_wang 已提交
601 602 603 604 605
| Name  | Type                     | Mandatory| Description                                                        |
| -------- | ------------------------- | ---- | ------------------------------------------------------------ |
| key      | string                    | Yes  | Key of the data. It cannot be empty.                               |
| value    | [ValueType](#valuetype)   | Yes  | Value to write. The value can be a number, a string, a Boolean value, or an array of numbers, strings, or Boolean values.|
| callback | AsyncCallback&lt;void&gt; | Yes  | Callback invoked to return the result. If the operation is successful, **err** is undefined. Otherwise, **err** is an error code.    |
A
annie_wangli 已提交
606

A
Annie_wang 已提交
607
**Example**
A
Annie_wang 已提交
608

A
Annie_wang 已提交
609
```js
A
Annie_wang 已提交
610 611 612 613 614 615 616 617 618 619 620
try {
    preferences.put('startup', 'auto', function (err) {
        if (err) {
            console.info("Failed to put the value of 'startup'. code =" + err.code + ", message =" + err.message);
            return;
        }
        console.info("Put the value of 'startup' successfully.");
    })
} catch (err) {
    console.info("Failed to put the value of 'startup'. code =" + err.code + ", message =" + err.message);
}
A
Annie_wang 已提交
621
```
A
annie_wangli 已提交
622 623 624 625 626 627


### put

put(key: string, value: ValueType): Promise&lt;void&gt;

A
Annie_wang 已提交
628
Writes data to this **Preferences** instance. This API uses a promise to return the result. You can use [flush](#flush) to make the **Preferences** instance persistent.
A
annie_wangli 已提交
629

A
Annie_wang 已提交
630
**System capability**: SystemCapability.DistributedDataManager.Preferences.Core
A
annie_wangli 已提交
631

A
Annie_wang 已提交
632
**Parameters**
A
Annie_wang 已提交
633

A
Annie_wang 已提交
634 635 636 637
| Name| Type                   | Mandatory| Description                                                        |
| ------ | ----------------------- | ---- | ------------------------------------------------------------ |
| key    | string                  | Yes  | Key of the data. It cannot be empty.                               |
| value  | [ValueType](#valuetype) | Yes  | Value to write. The value can be a number, a string, a Boolean value, or an array of numbers, strings, or Boolean values.|
A
annie_wangli 已提交
638

A
Annie_wang 已提交
639
**Return value**
A
Annie_wang 已提交
640

A
Annie_wang 已提交
641 642 643
| Type               | Description                     |
| ------------------- | ------------------------- |
| Promise&lt;void&gt; | Promise that returns no value.|
A
annie_wangli 已提交
644

A
Annie_wang 已提交
645
**Example**
A
Annie_wang 已提交
646

A
Annie_wang 已提交
647
```js
A
Annie_wang 已提交
648 649 650 651 652 653 654 655 656 657
try {
    let promise = preferences.put('startup', 'auto');
    promise.then(() => {
        console.info("Put the value of 'startup' successfully.");
    }).catch((err) => {
        console.info("Failed to put the value of 'startup'. code =" + err.code +", message =" + err.message);
    })
} catch(err) {
    console.info("Failed to put the value of 'startup'. code =" + err.code +", message =" + err.message);
}
A
Annie_wang 已提交
658
```
A
annie_wangli 已提交
659 660 661 662


### has

A
Annie_wang 已提交
663
has(key: string, callback: AsyncCallback&lt;boolean&gt;): void
A
annie_wangli 已提交
664

A
Annie_wang 已提交
665
Checks whether this **Preferences** instance contains a KV pair with the given key. This API uses an asynchronous callback to return the result..
A
annie_wangli 已提交
666

A
Annie_wang 已提交
667
**System capability**: SystemCapability.DistributedDataManager.Preferences.Core
A
annie_wangli 已提交
668

A
Annie_wang 已提交
669
**Parameters**
A
Annie_wang 已提交
670

A
Annie_wang 已提交
671 672 673 674
| Name  | Type                        | Mandatory| Description                                                        |
| -------- | ---------------------------- | ---- | ------------------------------------------------------------ |
| key      | string                       | Yes  | Key of the data to check. It cannot be empty.                             |
| callback | AsyncCallback&lt;boolean&gt; | Yes  | Callback invoked to return the result. If the **Preferences** instance contains the KV pair, **true** will be returned. Otherwise, **false** will be returned.|
A
annie_wangli 已提交
675

A
Annie_wang 已提交
676
**Example**
A
Annie_wang 已提交
677

A
Annie_wang 已提交
678
```js
A
Annie_wang 已提交
679 680 681 682 683 684 685 686 687 688 689 690 691 692 693
try {
    preferences.has('startup', function (err, val) {
        if (err) {
            console.info("Failed to check the key 'startup'. code =" + err.code + ", message =" + err.message);
            return;
        }
        if (val) {
            console.info("The key 'startup' is contained.");
        } else {
            console.info("The key 'startup' is not contained.");
        }
  })
} catch (err) {
    console.info("Failed to check the key 'startup'. code =" + err.code + ", message =" + err.message);
}
A
Annie_wang 已提交
694
```
A
annie_wangli 已提交
695 696 697 698 699 700


### has

has(key: string): Promise&lt;boolean&gt;

A
Annie_wang 已提交
701
Checks whether this **Preferences** instance contains a KV pair with the given key. This API uses a promise to return the result..
A
annie_wangli 已提交
702

A
Annie_wang 已提交
703
**System capability**: SystemCapability.DistributedDataManager.Preferences.Core
A
annie_wangli 已提交
704

A
Annie_wang 已提交
705
**Parameters**
A
Annie_wang 已提交
706

A
Annie_wang 已提交
707 708 709
| Name| Type  | Mandatory| Description                           |
| ------ | ------ | ---- | ------------------------------- |
| key    | string | Yes  | Key of the data to check. It cannot be empty.|
A
annie_wangli 已提交
710

A
Annie_wang 已提交
711
**Return value**
A
Annie_wang 已提交
712

A
Annie_wang 已提交
713 714 715
| Type                  | Description                                                        |
| ---------------------- | ------------------------------------------------------------ |
| Promise&lt;boolean&gt; | Promise used to return the result. If the **Preferences** instance contains the KV pair, **true** will be returned. Otherwise, **false** will be returned.|
A
annie_wangli 已提交
716

A
Annie_wang 已提交
717
**Example**
A
Annie_wang 已提交
718 719

```js
A
Annie_wang 已提交
720 721 722 723 724 725 726 727 728 729 730 731 732 733
try {
    let promise = preferences.has('startup');
    promise.then((val) => {
        if (val) {
            console.info("The key 'startup' is contained.");
        } else {
            console.info("The key 'startup' is not contained.");
        }
    }).catch((err) => {
        console.info("Failed to check the key 'startup'. code =" + err.code + ", message =" + err.message);
  })
} catch(err) {
    console.info("Failed to check the key 'startup'. code =" + err.code + ", message =" + err.message);
}
A
Annie_wang 已提交
734
```
A
annie_wangli 已提交
735 736 737 738 739 740


### delete

delete(key: string, callback: AsyncCallback&lt;void&gt;): void

A
Annie_wang 已提交
741
Deletes a KV pair from this **Preferences** instance based on the specified key. This API uses an asynchronous callback to return the result.
A
annie_wangli 已提交
742

A
Annie_wang 已提交
743
**System capability**: SystemCapability.DistributedDataManager.Preferences.Core
A
annie_wangli 已提交
744

A
Annie_wang 已提交
745
**Parameters**
A
Annie_wang 已提交
746

A
Annie_wang 已提交
747 748 749 750
| Name  | Type                     | Mandatory| Description                                                |
| -------- | ------------------------- | ---- | ---------------------------------------------------- |
| key      | string                    | Yes  | Key of the KV pair to delete. It cannot be empty.                     |
| callback | AsyncCallback&lt;void&gt; | Yes  | Callback invoked to return the result. If the operation is successful, **err** is **undefined**. Otherwise, **err** is an error code.|
A
annie_wangli 已提交
751

A
Annie_wang 已提交
752
**Example**
A
Annie_wang 已提交
753

A
Annie_wang 已提交
754
```js
A
Annie_wang 已提交
755 756 757 758 759 760 761 762 763 764 765
try {
    preferences.delete('startup', function (err) {
        if (err) {
            console.info("Failed to delete the key 'startup'. code =" + err.code + ", message =" + err.message);
            return;
        }
        console.info("Deleted the key 'startup'.");
    })
} catch (err) {
    console.info("Failed to delete the key 'startup'. code =" + err.code + ", message =" + err.message);
}
A
Annie_wang 已提交
766
```
A
annie_wangli 已提交
767 768 769 770 771 772


### delete

delete(key: string): Promise&lt;void&gt;

A
Annie_wang 已提交
773
Deletes a KV pair from this **Preferences** instance. This API uses a promise to return the result.
A
annie_wangli 已提交
774

A
Annie_wang 已提交
775
**System capability**: SystemCapability.DistributedDataManager.Preferences.Core
A
annie_wangli 已提交
776

A
Annie_wang 已提交
777
**Parameters**
A
Annie_wang 已提交
778

A
Annie_wang 已提交
779 780 781
| Name| Type  | Mandatory| Description                           |
| ------ | ------ | ---- | ------------------------------- |
| key    | string | Yes  | Key of the KV pair to delete. It cannot be empty.|
A
annie_wangli 已提交
782

A
Annie_wang 已提交
783
**Return value**
A
Annie_wang 已提交
784

A
Annie_wang 已提交
785 786 787
| Type               | Description                     |
| ------------------- | ------------------------- |
| Promise&lt;void&gt; | Promise that returns no value.|
A
annie_wangli 已提交
788

A
Annie_wang 已提交
789
**Example**
A
Annie_wang 已提交
790

A
Annie_wang 已提交
791
```js
A
Annie_wang 已提交
792 793 794 795 796 797 798 799 800 801
try {
    let promise = preferences.delete('startup');
	promise.then(() => {
        console.info("Deleted the key 'startup'.");
    }).catch((err) => {
        console.log("Failed to delete the key 'startup'. code =" + err.code +", message =" + err.message);
    })
} catch(err) {
    console.log("Failed to delete the key 'startup'. code =" + err.code +", message =" + err.message);
}
A
Annie_wang 已提交
802
```
A
annie_wangli 已提交
803 804 805 806 807 808


### flush

flush(callback: AsyncCallback&lt;void&gt;): void

A
Annie_wang 已提交
809
Saves the data of this **Preferences** instance to a file asynchronously. This API uses an asynchronous callback to return the result.
A
annie_wangli 已提交
810

A
Annie_wang 已提交
811
**System capability**: SystemCapability.DistributedDataManager.Preferences.Core
A
annie_wangli 已提交
812

A
Annie_wang 已提交
813
**Parameters**
A
Annie_wang 已提交
814

A
Annie_wang 已提交
815 816 817
| Name  | Type                     | Mandatory| Description                                                |
| -------- | ------------------------- | ---- | ---------------------------------------------------- |
| callback | AsyncCallback&lt;void&gt; | Yes  | Callback invoked to return the result. If the operation is successful, **err** is **undefined**. Otherwise, **err** is an error code.|
A
annie_wangli 已提交
818

A
Annie_wang 已提交
819
**Example**
A
Annie_wang 已提交
820

A
Annie_wang 已提交
821
```js
A
Annie_wang 已提交
822 823 824 825 826 827 828 829 830 831 832
try {
    preferences.flush(function (err) {
        if (err) {
            console.info("Failed to flush data. code =" + err.code + ", message =" + err.message);
            return;
        }
        console.info("Flushed data successfully.");
    })
} catch (err) {
    console.info("Failed to flush data. code =" + err.code + ", message =" + err.message);
}
A
Annie_wang 已提交
833
```
A
annie_wangli 已提交
834 835 836 837 838 839


### flush

flush(): Promise&lt;void&gt;

A
Annie_wang 已提交
840
Saves the data of this **Preferences** instance to a file asynchronously. This API uses a promise to return the result.
A
annie_wangli 已提交
841

A
Annie_wang 已提交
842
**System capability**: SystemCapability.DistributedDataManager.Preferences.Core
A
annie_wangli 已提交
843

A
Annie_wang 已提交
844
**Return value**
A
Annie_wang 已提交
845

A
Annie_wang 已提交
846 847 848
| Type               | Description                     |
| ------------------- | ------------------------- |
| Promise&lt;void&gt; | Promise that returns no value.|
A
annie_wangli 已提交
849

A
Annie_wang 已提交
850
**Example**
A
Annie_wang 已提交
851

A
Annie_wang 已提交
852
```js
A
Annie_wang 已提交
853 854 855 856 857 858 859 860 861 862
try {
    let promise = preferences.flush();
    promise.then(() => {
        console.info("Flushed data successfully.");
    }).catch((err) => {
        console.info("Failed to flush data. code =" + err.code + ", message =" + err.message);
    })
} catch (err) {
    console.info("Failed to flush data. code =" + err.code + ", message =" + err.message);
}
A
Annie_wang 已提交
863
```
A
annie_wangli 已提交
864 865 866 867 868 869


### clear

clear(callback: AsyncCallback&lt;void&gt;): void

A
Annie_wang 已提交
870
Clears this **Preferences** instance. This API uses an asynchronous callback to return the result.
A
annie_wangli 已提交
871

A
Annie_wang 已提交
872
**System capability**: SystemCapability.DistributedDataManager.Preferences.Core
A
annie_wangli 已提交
873

A
Annie_wang 已提交
874
**Parameters**
A
Annie_wang 已提交
875

A
Annie_wang 已提交
876 877 878
| Name  | Type                     | Mandatory| Description                                                |
| -------- | ------------------------- | ---- | ---------------------------------------------------- |
| callback | AsyncCallback&lt;void&gt; | Yes  | Callback invoked to return the result. If the operation is successful, **err** is **undefined**. Otherwise, **err** is an error code.|
A
annie_wangli 已提交
879

A
Annie_wang 已提交
880
**Example**
A
Annie_wang 已提交
881

A
Annie_wang 已提交
882
```js
A
Annie_wang 已提交
883 884 885 886 887 888 889 890 891 892 893
try {
	preferences.clear(function (err) {
        if (err) {
            console.info("Failed to clear data. code =" + err.code + ", message =" + err.message);
            return;
        }
        console.info("Cleared data successfully.");
    })
} catch (err) {
    console.info("Failed to clear data. code =" + err.code + ", message =" + err.message);
}
A
Annie_wang 已提交
894
```
A
annie_wangli 已提交
895 896 897 898 899 900


### clear

clear(): Promise&lt;void&gt;

A
Annie_wang 已提交
901
Clears this **Preferences** instance. This API uses a promise to return the result.
A
annie_wangli 已提交
902

A
Annie_wang 已提交
903
**System capability**: SystemCapability.DistributedDataManager.Preferences.Core
A
annie_wangli 已提交
904

A
Annie_wang 已提交
905
**Return value**
A
Annie_wang 已提交
906

A
Annie_wang 已提交
907 908 909
| Type               | Description                     |
| ------------------- | ------------------------- |
| Promise&lt;void&gt; | Promise that returns no value.|
A
annie_wangli 已提交
910

A
Annie_wang 已提交
911
**Example**
A
Annie_wang 已提交
912

A
Annie_wang 已提交
913
```js
A
Annie_wang 已提交
914 915 916 917 918 919 920 921 922 923
try {
    let promise = preferences.clear();
	promise.then(() => {
    	console.info("Cleared data successfully.");
    }).catch((err) => {
        console.info("Failed to clear data. code =" + err.code + ", message =" + err.message);
    })
} catch(err) {
    console.info("Failed to clear data. code =" + err.code + ", message =" + err.message);
}
A
Annie_wang 已提交
924
```
A
annie_wangli 已提交
925 926 927 928 929 930


### on('change')

on(type: 'change', callback: Callback&lt;{ key : string }&gt;): void

A
Annie_wang 已提交
931
Subscribes to data changes. A callback will be triggered to return the new value if the value of the subscribed key is changed and [flushed](#flush).
A
annie_wangli 已提交
932

A
Annie_wang 已提交
933
**System capability**: SystemCapability.DistributedDataManager.Preferences.Core
A
annie_wangli 已提交
934

A
Annie_wang 已提交
935
**Parameters**
A
Annie_wang 已提交
936

A
Annie_wang 已提交
937 938 939 940
| Name  | Type                            | Mandatory| Description                                    |
| -------- | -------------------------------- | ---- | ---------------------------------------- |
| type     | string                           | Yes  | Event type to subscribe to. The value **change** indicates data change events.|
| callback | Callback&lt;{ key : string }&gt; | Yes  | Callback invoked to return data changes.                          |
A
annie_wangli 已提交
941

A
Annie_wang 已提交
942
**Example**
A
Annie_wang 已提交
943

A
Annie_wang 已提交
944
```js
A
Annie_wang 已提交
945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973
try {
	data_preferences.getPreferences(this.context, 'mystore', function (err, preferences) {
		if (err) {
			console.info("Failed to get the preferences.");
			return;
		}
		let observer = function (key) {
			console.info("The key " + key + " changed.");
		}
		preferences.on('change', observer);
		preferences.put('startup', 'manual', function (err) {
			if (err) {
				console.info("Failed to put the value of 'startup'. Cause: " + err);
				return;
			}
			console.info("Put the value of 'startup' successfully.");

			preferences.flush(function (err) {
				if (err) {
					console.info("Failed to flush data. Cause: " + err);
					return;
				}
				console.info("Flushed data successfully.");
			})
		})
	})
} catch (err) {
	console.info("Failed to flush data. code =" + err.code + ", message =" + err.message);
}
A
Annie_wang 已提交
974
```
A
annie_wangli 已提交
975 976 977 978


### off('change')

A
Annie_wang 已提交
979
off(type: 'change', callback?: Callback&lt;{ key : string }&gt;): void
A
annie_wangli 已提交
980

A
Annie_wang 已提交
981
Unsubscribes from data changes.
A
annie_wangli 已提交
982

A
Annie_wang 已提交
983
**System capability**: SystemCapability.DistributedDataManager.Preferences.Core
A
annie_wangli 已提交
984

A
Annie_wang 已提交
985
**Parameters**
A
Annie_wang 已提交
986

A
Annie_wang 已提交
987 988 989 990
| Name  | Type                            | Mandatory| Description                                      |
| -------- | -------------------------------- | ---- | ------------------------------------------ |
| type     | string                           | Yes  | Event type to unsubscribe from. The value **change** indicates data change events.  |
| callback | Callback&lt;{ key : string }&gt; | No  | Callback to unregister. If this parameter is left blank, the callbacks used to subscribing to all data changes will be unregistered.|
A
annie_wangli 已提交
991

A
Annie_wang 已提交
992
**Example**
A
Annie_wang 已提交
993

A
Annie_wang 已提交
994
```js
A
Annie_wang 已提交
995 996
try {
    data_preferences.getPreferences(this.context, 'mystore', function (err, preferences) {
A
Annie_wang 已提交
997
        if (err) {
A
Annie_wang 已提交
998
            console.info("Failed to get the preferences.");
A
Annie_wang 已提交
999
            return;
A
Annie_wang 已提交
1000
        }
A
Annie_wang 已提交
1001 1002 1003 1004 1005
        let observer = function (key) {
            console.info("The key " + key + " changed.");
        }
        preferences.on('change', observer);
        preferences.put('startup', 'auto', function (err) {
A
Annie_wang 已提交
1006
            if (err) {
A
Annie_wang 已提交
1007
                console.info("Failed to put the value of 'startup'. Cause: " + err);
A
Annie_wang 已提交
1008
                return;
A
Annie_wang 已提交
1009
            }
A
Annie_wang 已提交
1010 1011 1012 1013 1014 1015 1016 1017 1018 1019
            console.info("Put the value of 'startup' successfully.");

            preferences.flush(function (err) {
                if (err) {
                    console.info("Failed to flush data. Cause: " + err);
                    return;
                }
                console.info("Flushed data successfully.");
            })
            preferences.off('change', observer);
A
Annie_wang 已提交
1020
        })
A
Annie_wang 已提交
1021
    })
A
Annie_wang 已提交
1022 1023 1024
} catch (err) {
    console.info("Failed to flush data. code =" + err.code + ", message =" + err.message);
}
A
Annie_wang 已提交
1025
```
A
Annie_wang 已提交
1026 1027 1028

## ValueType

A
Annie_wang 已提交
1029
Enumerates the value types.
A
Annie_wang 已提交
1030

A
Annie_wang 已提交
1031
**System capability**: SystemCapability.DistributedDataManager.Preferences.Core
A
Annie_wang 已提交
1032

A
Annie_wang 已提交
1033 1034 1035 1036 1037
| Type           | Description                          |
| --------------- | ------------------------------ |
| number          | The value is a number.            |
| string          | The value is a string.          |
| boolean         | The value is of Boolean type.          |
A
Annie_wang 已提交
1038 1039 1040
| Array\<number>  | The value is an array of numbers.  |
| Array\<boolean> | The value is a Boolean array.  |
| Array\<string>  | The value is an array of the strings.|