harmony 鸿蒙$$ Syntax: Two-Way Synchronization of Built-in Components

2023-06-24 浏览 (1034)

$$ Syntax: Two-Way Synchronization of Built-in Components

The $$ operator provides a TS variable by-reference to a built-in component so that the variable value and the internal state of that component are kept in sync.

What the internal state is depends on the component. For example, for the bindPopup attribute method, it is the show parameter.

Rules of Use

  • $$ supports variables of simple types and variables decorated by @State, @Link, or @Prop.

  • $$ supports the components listed below.

ComponentSupported Parameter/AttributeInitial API Version
Checkboxselect10
CheckboxGroupselectAll10
DatePickerselected10
TimePickerselected10
MenuItemselected10
Panelmode10
Radiochecked10
Ratingrating10
Searchvalue10
SideBarContainershowSideBar10
Slidervalue10
Stepperindex10
SwiperisOn10
Tabsindex10
TextAreatext10
TextInputtext10
TextPickerselected, value10
ToggleisOn10
AlphabetIndexerselected10
Selectselected, value10
BindSheetisShow10
BindContentCoverisShow10
bindPopupshow8
Refreshrefreshing8
  • When the variable bound to $$ changes, the UI is re-rendered synchronously.

Example

This example uses the text parameter of the <TextInput> component.

// xxx.ets
@Entry
@Component
struct TextInputExample {
  @State text: string = ''
  controller: TextInputController = new TextInputController()

  build() {
    Column({ space: 20 }) {
      Text(this.text)
      TextInput({ text: $$this.text, placeholder: 'input your word...', controller: this.controller })
        .placeholderColor(Color.Grey)
        .placeholderFont({ size: 14, weight: 400 })
        .caretColor(Color.Blue)
        .width(300)
    }.width('100%').height('100%').justifyContent(FlexAlign.Center)
  }
}

TextInputDouble

你可能感兴趣的鸿蒙文章

harmony 鸿蒙Quick Start

harmony 鸿蒙app.json5 Configuration File

harmony 鸿蒙Internal Structure of the app Tag

harmony 鸿蒙Application Configuration File Overview (FA Model)

harmony 鸿蒙Application Configuration File Overview (Stage Model)

harmony 鸿蒙Application Installation and Uninstallation Process

harmony 鸿蒙Application Package Overview

harmony 鸿蒙Application Package Structure in FA Model

harmony 鸿蒙Application Package Structure in Stage Model

harmony 鸿蒙Application Package Update Process

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