W3Cschool
恭喜您成為首批注冊(cè)用戶(hù)
獲得88經(jīng)驗(yàn)值獎(jiǎng)勵(lì)
在卡片頁(yè)面中可以通過(guò)postCardAction接口觸發(fā)message事件拉起FormExtensionAbility,然后由FormExtensionAbility刷新卡片內(nèi)容,下面是這種刷新方式的簡(jiǎn)單示例。
- let storage = new LocalStorage();
- @Entry(storage)
- @Component
- struct WidgetCard {
- @LocalStorageProp('title') title: string = 'init';
- @LocalStorageProp('detail') detail: string = 'init';
- build() {
- Column() {
- Button('刷新')
- .onClick(() => {
- postCardAction(this, {
- 'action': 'message',
- 'params': {
- 'msgTest': 'messageEvent'
- }
- });
- })
- Text(`${this.title}`)
- Text(`${this.detail}`)
- }
- .width('100%')
- .height('100%')
- }
- }
- import formBindingData from '@ohos.app.form.formBindingData';
- import FormExtensionAbility from '@ohos.app.form.FormExtensionAbility';
- import formProvider from '@ohos.app.form.formProvider';
- export default class EntryFormAbility extends FormExtensionAbility {
- onFormEvent(formId, message) {
- // Called when a specified message event defined by the form provider is triggered.
- console.info(`FormAbility onEvent, formId = ${formId}, message: ${JSON.stringify(message)}`);
- let formData = {
- 'title': 'Title Update Success.', // 和卡片布局中對(duì)應(yīng)
- 'detail': 'Detail Update Success.', // 和卡片布局中對(duì)應(yīng)
- };
- let formInfo = formBindingData.createFormBindingData(formData)
- formProvider.updateForm(formId, formInfo).then((data) => {
- console.info('FormAbility updateForm success.' + JSON.stringify(data));
- }).catch((error) => {
- console.error('FormAbility updateForm failed: ' + JSON.stringify(error));
- })
- }
- ...
- }
運(yùn)行效果如下圖所示。
Copyright©2021 w3cschool編程獅|閩ICP備15016281號(hào)-3|閩公網(wǎng)安備35020302033924號(hào)
違法和不良信息舉報(bào)電話(huà):173-0602-2364|舉報(bào)郵箱:jubao@eeedong.com
掃描二維碼
下載編程獅App
編程獅公眾號(hào)
聯(lián)系方式:
更多建議: