Harmony arkTs组件开发:ListItem控件中不能使用多个组件

如下代码:

List(){
  ForEach(this.indexList, (item: number) =>{
    ListItem(){
      Text("测试")
      Row(){
        Image(this.images[item])
          .width(20)
          .height(20)
          .margin({left:15})
        Text(this.arr[item])
          //.width('80%')
          .fontSize(sizes.oneFontSize)
          .fontColor(colors.TitleTextColor)
          .margin({left:5.5})
          .textOverflow({overflow: TextOverflow.Ellipsis })
          .maxLines(1)
          .layoutWeight(1)
        Image($r("app.media.mine_qrcode_arrow"))
          .width(10)
          .height(10)
          .margin({right:15})
      }
      .width('100%')
    }
    .height(60)
    .onClick((event:ClickEvent)=>{
      let index= this.indexList.indexOf(item);
      console.info("onClick index="+`${index}`)
    })
  })
}
.width('100%')
.height(60*(this.arr.length))
.margin({top:2})
.divider({strokeWidth:0.5, color:colors.grayLineBackgroundColor})

标红的代码会导致编译错误:

The 'ListItem' component can have only one child component. <ArkTSCheck>

解决思路:

把button、Text、Image等组件放到一个容器组件里,如Row、Column、Stack中,这样就能正常编译了。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值