• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# @ohos.app.form.formBindingData (卡片数据绑定类)
2
3<!--Kit: Form Kit-->
4<!--Subsystem: Ability-->
5<!--Owner: @cx983299475-->
6<!--Designer: @xueyulong-->
7<!--Tester: @chenmingze-->
8<!--Adviser: @Brilliantry_Rui-->
9卡片数据绑定模块提供卡片数据绑定的能力。包括FormBindingData对象的创建、相关信息的描述。
10
11> **说明:**
12>
13> 本模块首批接口从API version 9开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
14
15## 导入模块
16
17```ts
18import { formBindingData } from '@kit.FormKit';
19```
20
21
22## ProxyData<sup>10+</sup>
23
24卡片代理刷新订阅数据信息。
25
26**模型约束:** 此接口仅可在Stage模型下使用。
27
28**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
29
30**系统能力:** SystemCapability.Ability.Form
31
32| 名称 | 类型 | 必填 | 说明 |
33| -------- | -------- | -------- | -------- |
34| key<sup>10+</sup> | string | 是 | 卡片代理刷新的订阅标识,与数据发布者保持一致。|
35| subscriberId<sup>10+</sup> | string | 否 | 卡片代理刷新的订阅条件,默认值为当前卡片的formId。|
36
37
38## FormBindingData
39
40FormBindingData相关描述。
41
42**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
43
44**系统能力:** SystemCapability.Ability.Form
45
46| 名称 | 类型 | 必填 | 说明 |
47| -------- | -------- | -------- | -------- |
48| data | Object | 是 | 卡片要展示的数据。可以是包含若干键值对的Object或者 json 格式的字符串。|
49| proxies<sup>10+</sup> | Array<[ProxyData](#proxydata10)> | 否 | 卡片代理刷新的订阅信息,默认为空数组。<br>**模型约束:** 此接口仅可在Stage模型下使用。<br>|
50
51## formBindingData.createFormBindingData
52
53createFormBindingData(obj?: Object | string): FormBindingData
54
55创建一个FormBindingData对象。
56
57**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
58
59**系统能力:** SystemCapability.Ability.Form
60
61**参数:**
62
63| 参数名 | 类型           | 必填 | 说明                                                         |
64| ------ | -------------- | ---- | ------------------------------------------------------------ |
65| obj    | Object\|string | 否   | 卡片要展示的数据。可以是包含若干键值对的Object或者 json 格式的字符串。其中图片数据以'formImages'作为标识,内容为图片标识与图片文件描述符的键值对{'formImages': {'key1': fd1, 'key2': fd2}}。<br>**说明:** 在[卡片刷新](../../form/arkts-ui-widget-interaction-overview.md)过程中,卡片UI通过@LocalStorageProp接收卡片数据时,FormBindingData对象会序列化,即卡片数据会转换成string类型。从API version 20开始,图片文件数量上限为20张,所有图片总内存大小不超过10MB,超出限制的图片会显示异常,API version 19及之前的版本,图片文件数量上限为5张,每张限制内存2MB。 |
66
67
68**返回值:**
69
70| 类型                                | 说明                                    |
71| ----------------------------------- | --------------------------------------- |
72| [FormBindingData](#formbindingdata) | 根据传入数据创建的FormBindingData对象。 |
73
74**错误码:**
75
76以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。
77
78| 错误码ID | 错误信息 |
79| -------- | -------- |
80| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types; 3.Parameter verification failed. |
81
82
83**示例:**
84
85```ts
86import { formBindingData } from '@kit.FormKit';
87import { fileIo } from '@kit.CoreFileKit';
88import { common } from '@kit.AbilityKit';
89@Entry
90@Component
91struct Index {
92  content = this.getUIContext().getHostContext() as common.UIAbilityContext;
93  pathDir: string = this.content.filesDir;
94  createFormBindingData() {
95    try {
96      let filePath = this.pathDir + "/form.png";
97      let file = fileIo.openSync(filePath);
98      let formImagesParam: Record<string, number> = {
99        'image': file.fd
100      };
101      let createFormBindingDataParam: Record<string, string | Record<string, number>> = {
102        'name': '21°',
103        'imgSrc': 'image',
104        'formImages': formImagesParam
105      };
106      formBindingData.createFormBindingData(createFormBindingDataParam);
107    } catch (error) {
108      console.error(`catch error, error: ${JSON.stringify(error)}`);
109    }
110  }
111  build() {
112    Button('createFormBindingData')
113      .onClick((event: ClickEvent)=>{
114        this.createFormBindingData();
115      })
116  }
117}
118```
119