#鸿蒙学习大百科#如何获取RichEditor内span信息?

如何获取RichEditor内span信息?

HarmonyOS
2024-10-26 09:31:44
浏览
收藏 0
回答 1
回答 1
按赞同
/
按时间
天涯独一隅

可通过getSpans获取组件内span信息。

@Entry
@Component
struct Index {
  my_builder: CustomBuilder|undefined = undefined;
  controller: RichEditorController = new RichEditorController();
  options: RichEditorOptions = { controller: this.controller };
  build() {
    Column() {
      RichEditor(this.options)
        .onReady(() => {
          this.controller.addTextSpan('点击按钮获取此处span信息。', {
            style: {
              fontColor: Color.Black,
              fontSize: 15
            }
          })
        })
        .width(300)
        .height(50)
      Text('查看getSpans返回值:').fontSize(10).fontColor(Color.Gray).width(300)
      RichEditor(this.options)
        .width(300)
        .height(50)
      Button('getSpans', {
        buttonStyle: ButtonStyleMode.NORMAL
      })
        .height(30)
        .fontSize(13)
        .onClick(() => {
          this.controller.addTextSpan(JSON.stringify(this.controller.getSpans()), {
            style: {
              fontColor: Color.Gray,
              fontSize: 10
            }
          })

        })
    }
    .width('100%')
    .height('100%')
    .justifyContent(FlexAlign.Center)

  }
}
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.
  • 28.
  • 29.
  • 30.
  • 31.
  • 32.
  • 33.
  • 34.
  • 35.
  • 36.
  • 37.
  • 38.
  • 39.
  • 40.
  • 41.
  • 42.
  • 43.
  • 44.
分享
微博
QQ
微信
回复
2024-10-26 17:42:27
相关问题