ets拿不到组件实例,无法获取组件的值,获取组件值参考如下:@Entry @Component struct Index2 { private select: number = 0 private fruits: string[] = ['apple1', 'orange2', 'peach3', 'grape4'] private defaultValue: string = '' aboutToAppear(): void { this.defaultValue = this.fruits[this.select] console.log(this.fruits.toString()+"★") } build() { Column() { Text('Whether to change a text?').fontSize(16).margin({ bottom: 10 }) Column() { TextPicker({ range: this.fruits }) .onChange((value: string | string[], index: number | number[]) => { // console.info('Picker item changed, value: ' + value + ', index: ' + index) this.defaultValue = value.toString() console.info('defaultValue是' + this.defaultValue) }) .disappearTextStyle({ color: Color.Red, font: { size: 15, weight: FontWeight.Lighter } }) .textStyle({ color: Color.Black, font: { size: 20, weight: FontWeight.Normal } }) .selectedTextStyle({ color: Color.Blue, font: { size: 30, weight: FontWeight.Bolder } }) } Flex({ justifyContent: FlexAlign.SpaceAround }) { Button('cancel') .onClick(() => { }).backgroundColor(0xffffff).fontColor(Color.Black) Button('confirm') .onClick(() => { console.log(this.defaultValue) }).backgroundColor(0xffffff).fontColor(Color.Red) } } }TextPicker没有初始化完成事件,只能遍历数据,传的值在数据源中,则默认值为传的值,否则,默认值为为数据源第一条记录。
ets拿不到组件实例,无法获取组件的值,获取组件值参考如下:
TextPicker没有初始化完成事件,只能遍历数据,传的值在数据源中,则默认值为传的值,否则,默认值为为数据源第一条记录。