openharmony 鸿蒙 js-apis-app-form-formBindingData

2025-06-12 浏览 (1)

@ohos.app.form.formBindingData (formBindingData)

The FormBindingData module provides APIs for widget data binding. You can use the APIs to create a FormBindingData object and obtain related information.

NOTE

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.

Modules to Import

import { formBindingData } from '@kit.FormKit';

ProxyData10+

Defines the subscription information about the widget update by proxy.

Model restriction: This API can be used only in the stage model.

Atomic service API: This API can be used in atomic services since API version 11.

System capability: SystemCapability.Ability.Form

NameTypeMandatoryDescription
key10+stringYesSubscriber ID of the widget update by proxy. The value is the same as that of the data publisher.
subscriberId10+stringNoSubscription condition of the widget update by proxy. The default value is the current widget ID (specified by formId).

FormBindingData

Describes a FormBindingData object.

Atomic service API: This API can be used in atomic services since API version 11.

System capability: SystemCapability.Ability.Form

NameTypeMandatoryDescription
dataObjectYesData to be displayed on the widget. The value can be an object containing multiple key-value pairs or a string in JSON format.
proxies10+Array<ProxyData>NoSubscription information of the widget update by proxy. The default value is an empty array.
Model restriction: This API can be used only in the stage model.

formBindingData.createFormBindingData

createFormBindingData(obj?: Object|string): FormBindingData

Creates a FormBindingData object.

Atomic service API: This API can be used in atomic services since API version 11.

System capability: SystemCapability.Ability.Form

Parameters

NameTypeMandatoryDescription
objObject|stringNoData to be displayed on the widget. The value can be an object containing multiple key-value pairs or a string in JSON format. The image data is identified by 'formImages', and the content is multiple key-value pairs, each of which consists of an image identifier and image file descriptor. The final format is {'formImages': {'key1': fd1, 'key2': fd2}}.

Return value

TypeDescription
FormBindingDataFormBindingData object created based on the passed data.

Error codes

For details about the error codes, see Universal Error Codes.

IDError Message
401Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types; 3.Parameter verification failed

Example

import { formBindingData } from '@kit.FormKit';
import { BusinessError } from '@kit.BasicServicesKit';
import { fileIo } from '@kit.CoreFileKit';

try {
  let file = fileIo.openSync('/path/to/form.png');
  let formImagesParam: Record<string, number> = {
    'image': file.fd
  };
  let createFormBindingDataParam: Record<string, string|Object> = {
    'name': '21°',
    'imgSrc': 'image',
    'formImages': formImagesParam
  };

  formBindingData.createFormBindingData(createFormBindingDataParam);
} catch (error) {
  let code = (error as BusinessError).code;
  let message = (error as BusinessError).message;
  console.error(`catch error, code: ${code}, message: ${message}`);
}

你可能感兴趣的鸿蒙文章

harmony 鸿蒙Form Kit

harmony 鸿蒙Form Error Codes

harmony 鸿蒙@ohos.app.form.formAgent (FormAgent) (System API)

harmony 鸿蒙@ohos.app.form.FormEditExtensionAbility (FormEditExtensionAbility)

harmony 鸿蒙@ohos.app.form.FormExtensionAbility (FormExtensionAbility) (System API)

harmony 鸿蒙@ohos.app.form.FormExtensionAbility (FormExtensionAbility)

harmony 鸿蒙@ohos.app.form.formHost (formHost) (System API)

harmony 鸿蒙@ohos.app.form.formInfo (formInfo) (System API)

harmony 鸿蒙@ohos.app.form.formInfo (formInfo)

harmony 鸿蒙@ohos.app.form.formObserver (formObserver) (System API)

  • 所属分类: 后端技术
  • 本文标签: 鸿蒙 软件
  • 版权声明: 本文链接 https://seaxiang.com/blog/o46a7L