可以通过如下方式实现:private textPickerValue: string = ''; private textPickerIndex: number = 0; .onChange((value: string | string[], index: number | number[]) => { if (Array.isArray(value)) { this.textPickerValue= value[0]; } else { this.textPickerValue= value; } if (Array.isArray(index)) { this.textPickerIndex= index[0]; } else { this.textPickerIndex= index; } console.info('Picker item changed, value: ' + this.textPickerValue+ ', index: ' + this.textPickerIndex) })onChange参数返回的就是选中数据,是单选返回的就是字符,多选返回的就是数组,具体看使用场景,可以当做字符使用也可以当做数组使用。可参照API文档:https://developer.huawei.com/consumer/cn/doc/harmonyos-references-V5/ts-basic-components-textpicker-V5\#%E7%A4%BA%E4%BE%8B
可以通过如下方式实现:
onChange参数返回的就是选中数据,是单选返回的就是字符,多选返回的就是数组,具体看使用场景,可以当做字符使用也可以当做数组使用。
可参照API文档:https://developer.huawei.com/consumer/cn/doc/harmonyos-references-V5/ts-basic-components-textpicker-V5\#%E7%A4%BA%E4%BE%8B