openharmony 鸿蒙 arkts-two-way-sync

2025-06-16 浏览 (1)

$$语法:系统组件双向同步

$$运算符为系统组件提供TS变量的引用,使得TS变量和系统组件的内部状态保持同步。

内部状态具体指什么取决于组件。例如,TextInput组件的text参数。

说明:

$$还用于@Builder装饰器的按引用传递参数,开发者需要注意两种用法的区别。

使用规则

  • 当前$$支持基础类型变量,以及@State@Link@Prop装饰的变量。

  • 当前$$支持的组件:

组件支持的参数/属性起始API版本
Checkboxselect10
CheckboxGroupselectAll10
DatePickerselected10
TimePickerselected10
MenuItemselected10
Panelmode10
Radiochecked10
Ratingrating10
Searchvalue10
SideBarContainershowSideBar10
Slidervalue10
Stepperindex10
Swiperindex10
Tabsindex10
TextAreatext10
TextInputtext10
TextPickerselected、value10
ToggleisOn10
AlphabetIndexerselected10
Selectselected、value10
BindSheetisShow10
BindContentCoverisShow10
Refreshrefreshing8
GridItemselected10
ListItemselected10
  • $$绑定的变量变化时,会触发UI的同步刷新。

使用示例

TextInput方法的text参数为例:

// 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 鸿蒙@AnimatableExtend装饰器:定义可动画属性

harmony 鸿蒙管理应用拥有的状态概述

harmony 鸿蒙AppStorage:应用全局的UI状态存储

harmony 鸿蒙基本语法概述

harmony 鸿蒙@Builder装饰器:自定义构建函数

harmony 鸿蒙@BuilderParam装饰器:引用@Builder函数

harmony 鸿蒙创建自定义组件

harmony 鸿蒙自定义组件混用场景指导

harmony 鸿蒙自定义组件成员属性访问限定符使用限制

harmony 鸿蒙自定义组件冻结功能

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