【HarmonyOs Arkts笔记】Arkts ForEach循环使用

在这里插入图片描述

说明

ForEach循环数组对象时 要指定对象的唯一标识 例如 id,否则只会显示第一个

@State tabsList: object[] = [
    {
    name: '砍价活动', id: 1, icon: 'https://php-b2c.likeshop.cn/uploads/images/2022062414322367e6a5479.png' },
    {
    name: '拼团活动', id: 2, icon: 'https://php-b2c.likeshop.cn/uploads/images/20220624143223798a31616.png' },
    {
    name: '限时秒杀', id: 3, icon: 'https://php-b2c.likeshop.cn/uploads/images/202206241432233bf9e9321.png' },
    {
    name: '热销榜单', id: 4, icon: 'https://php-b2c.likeshop.cn/uploads/images/20220624143223839e33279.png' },
  ]
/*金刚区*/
      Grid() {
        ForEach(this.tabsList, (item: any) => {
          GridItem() {
            Column() {
              Image(item.icon)
                .width(30)
                .height(30)
              Text(item.name)
                .margin({ top: 10 })
                .fontSize(12)
            }
          }
          // 必须加上对象的唯一标识  例如 id
        }, item => item.id)
      }
      .columnsTemplate('1fr 1fr 1fr 1fr 1fr')
      .rowsTemplate('1fr 1fr')
      .columnsGap(10)
      .rowsGap(10)
      .backgroundColor(0xFAEEE0)
      .height(200)
      .borderRadius(10)
      .margin({ top: 10 })
      .padding(10)

相关推荐

  1. 笔记:Python 循环结构练习题

    2023-12-31 09:42:04       12 阅读
  2. 循环使用dict和set

    2023-12-31 09:42:04       10 阅读
  3. python学习笔记10(循环结构2)

    2023-12-31 09:42:04       40 阅读
  4. 笔记:Python循环结构编程题(练习题)

    2023-12-31 09:42:04       10 阅读
  5. 机器学习笔记——循环神经网络

    2023-12-31 09:42:04       8 阅读

最近更新

  1. TCP协议是安全的吗?

    2023-12-31 09:42:04       16 阅读
  2. 阿里云服务器执行yum,一直下载docker-ce-stable失败

    2023-12-31 09:42:04       16 阅读
  3. 【Python教程】压缩PDF文件大小

    2023-12-31 09:42:04       15 阅读
  4. 通过文章id递归查询所有评论(xml)

    2023-12-31 09:42:04       18 阅读

热门阅读

  1. Python-01-print、input、#

    2023-12-31 09:42:04       43 阅读
  2. kafka-python简单生产消费数据

    2023-12-31 09:42:04       47 阅读
  3. 基于单片机的公交车站自动报站器设计与实现

    2023-12-31 09:42:04       38 阅读
  4. MybatisPlus之常用插件的使用

    2023-12-31 09:42:04       29 阅读
  5. Spring Boot IO官方文档中文版

    2023-12-31 09:42:04       27 阅读
  6. vue、react、angular 区别

    2023-12-31 09:42:04       34 阅读
  7. delphi中format日期格式的小要点

    2023-12-31 09:42:04       37 阅读
  8. Ubuntu 系统中安装和配置 clash

    2023-12-31 09:42:04       35 阅读
  9. 设计模式之观察者模式

    2023-12-31 09:42:04       32 阅读