1e41f4b71Sopenharmony_ci# list 2e41f4b71Sopenharmony_ci 3e41f4b71Sopenharmony_ci> **说明:** 4e41f4b71Sopenharmony_ci> 从API version 4开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。 5e41f4b71Sopenharmony_ci 6e41f4b71Sopenharmony_ci列表包含一系列相同宽度的列表项。适合连续、多行呈现同类数据,例如图片和文本。 7e41f4b71Sopenharmony_ci 8e41f4b71Sopenharmony_ci## 权限列表 9e41f4b71Sopenharmony_ci 10e41f4b71Sopenharmony_ci无 11e41f4b71Sopenharmony_ci 12e41f4b71Sopenharmony_ci 13e41f4b71Sopenharmony_ci## 子组件 14e41f4b71Sopenharmony_ci 15e41f4b71Sopenharmony_ci仅支持<[list-item-group](js-components-container-list-item-group.md)>和<[list-item](js-components-container-list-item.md)>。 16e41f4b71Sopenharmony_ci 17e41f4b71Sopenharmony_ci 18e41f4b71Sopenharmony_ci## 属性 19e41f4b71Sopenharmony_ci 20e41f4b71Sopenharmony_ci除支持[通用属性](js-components-common-attributes.md)外,还支持如下属性: 21e41f4b71Sopenharmony_ci 22e41f4b71Sopenharmony_ci| 名称 | 类型 | 默认值 | 必填 | 描述 | 23e41f4b71Sopenharmony_ci| --------------------------- | ---------------------------------------- | ------- | ---- | ---------------------------------------- | 24e41f4b71Sopenharmony_ci| scrollpage | boolean | false | 否 | 设置为true时,将 list 顶部页面中非 list 部分随 list 一起滑出可视区域,当list方向为row时,不支持此属性。 | 25e41f4b71Sopenharmony_ci| cachedcount | number | 0 | 否 | 长列表延迟加载时list-item最少缓存数量。<br/>可视区域外缓存的list-item数量少于该值时,会触发requestitem事件。 | 26e41f4b71Sopenharmony_ci| scrollbar | string | off | 否 | 侧边滑动栏的显示模式(当前只支持纵向):<br/>- off:不显示。<br/>- auto:按需显示(触摸时显示,2s后消失)。<br/>- on:常驻显示。 | 27e41f4b71Sopenharmony_ci| scrolleffect | string | spring | 否 | 滑动效果,目前支持如下滑动效果:<br/>- spring:弹性物理动效,滑动到边缘后可以根据初始速度或通过触摸事件继续滑动一段距离,松手后回弹。<br/>- fade:渐隐物理动效,滑动到边缘后展示一个波浪形的渐隐,根据速度和滑动距离的变化渐隐也会发送一定的变化。<br/>- no:滑动到边缘后无效果。 | 28e41f4b71Sopenharmony_ci| indexer | boolean \| Array<string> | false | 否 | 是否展示侧边栏快速字母索引栏。设置为true或者自定义索引时,索引栏会显示在列表右边界处。示例:<br/>"indexer" : "true"表示使用默认字母索引表。<br/>"indexer" : "false"表示无索引。<br/>"indexer" : ['\#',‘1’,'2',‘3’,'4',‘5’,'6',‘7’,'8']表示自定义索引表。自定义时"\#"必须要存在。<br/>indexer属性生效需要flex-direction属性配合设置为column,且columns属性设置为1。<br/>点击索引条进行列表项索引需要list-item子组件配合设置相应的[section属性](js-components-container-list-item.md#属性)。 | 29e41f4b71Sopenharmony_ci| indexercircle<sup>5+</sup> | boolean | - | 否 | 是否为环形索引。<br/>穿戴设备默认为true,其他为false。indexer为false时不生效。 | 30e41f4b71Sopenharmony_ci| indexermulti<sup>5+</sup> | boolean | false | 否 | 是否开启索引条多语言功能。<br/>indexer为false时不生效。 | 31e41f4b71Sopenharmony_ci| indexerbubble<sup>5+</sup> | boolean | true | 否 | 是否开启索引切换的气泡提示。<br/>indexer为false时不生效。 | 32e41f4b71Sopenharmony_ci| divider<sup>5+</sup> | boolean | false | 否 | item是否自带分隔线。<br/>其样式参考样式列表的divider-color、divider-height、divider-length、divider-origin。 | 33e41f4b71Sopenharmony_ci| shapemode | string | default | 否 | 侧边滑动栏的形状类型。<br/>- default:不指定,跟随主题;<br/>- rect:矩形;<br/>- round:圆形。 | 34e41f4b71Sopenharmony_ci| updateeffect | boolean | false | 否 | 用于设置当list内部的item发生删除或新增时是否支持动效。<br/>- false:新增删除item时无过渡动效。<br/>- true:新增删除item时播放过程动效。 | 35e41f4b71Sopenharmony_ci| chainanimation<sup>5+</sup> | boolean | false | 否 | 用于设置当前list是否启用链式联动动效,开启后列表滑动以及顶部和底部拖拽时会有链式联动的效果。链式联动效果:list内的list-item间隔一定距离,在基本的滑动交互行为下,主动对象驱动从动对象进行联动,驱动效果遵循弹簧物理动效。<br/>- false:不启用链式联动<br/>- true:启用链式联动<br/>不支持动态修改。<br/>同时配置了indexer,链式动效不生效。<br/>如配置了链式动效,list-item的sticky不生效。 | 36e41f4b71Sopenharmony_ci| initialindex | number | 0 | 否 | 用于设置当前List初次加载时视口起始位置显示的item,默认为0,即显示第一个item,如设置的序号超过了最后一个item的序号,则设置不生效,当同时设置了initialoffset属性时,当前属性不生效。当indexer为true或者scrollpage为true时,不生效。 | 37e41f4b71Sopenharmony_ci| initialoffset | <length> | 0 | 否 | 用于设置当前List初次加载时视口的起始偏移量,偏移量无法超过当前List可滑动的范围,如果超过会被截断为可滑动范围的极限值。当indexer为true或者scrollpage为true时,不生效。 | 38e41f4b71Sopenharmony_ci| selected<sup>5+</sup> | string | - | 否 | 指定当前列表中被选中激活的项,可选值为list-item的section属性值。 | 39e41f4b71Sopenharmony_ci 40e41f4b71Sopenharmony_ci 41e41f4b71Sopenharmony_ci## 样式 42e41f4b71Sopenharmony_ci 43e41f4b71Sopenharmony_ci除支持[通用样式](js-components-common-styles.md)外,还支持如下样式: 44e41f4b71Sopenharmony_ci 45e41f4b71Sopenharmony_ci| 名称 | 类型 | 默认值 | 必填 | 描述 | 46e41f4b71Sopenharmony_ci| ----------------------------- | ---------------------------------------- | ----------- | ---- | ---------------------------------------- | 47e41f4b71Sopenharmony_ci| divider-color<sup>5+</sup> | <color> | transparent | 否 | item分隔线颜色,仅当list的divider属性为true时生效。 | 48e41f4b71Sopenharmony_ci| divider-height<sup>5+</sup> | <length> | 1 | 否 | item分隔线高度,仅当list的divider属性为true时生效。 | 49e41f4b71Sopenharmony_ci| divider-length<sup>5+</sup> | <length> | 主轴宽度 | 否 | item分隔线长度,不设置时最大长度为主轴宽度,具体长度取决于divider-origin,仅当list的divider属性为true时生效。 | 50e41f4b71Sopenharmony_ci| divider-origin<sup>5+</sup> | <length> | 0 | 否 | item分隔线相对于item主轴起点位置的偏移量,仅当list的divider属性为true时生效。 | 51e41f4b71Sopenharmony_ci| flex-direction | string | column | 否 | 设置flex容器主轴的方向,指定flex项如何放置在flex容器中,可选值为:<br/>- column:主轴为纵向。<br/>- row:主轴为横向。<br/>其他组件默认值为row,在list组件中默认值为column。 | 52e41f4b71Sopenharmony_ci| columns | number | 1 | 否 | list交叉轴方向的显示列数,默认为1列。<br/>设置多列时,在list交叉轴上进行均分,每一列大小相同。 | 53e41f4b71Sopenharmony_ci| align-items | string | stretch | 否 | list每一列交叉轴上的对齐格式,可选值为:<br/>- stretch:弹性元素被在交叉轴方向被拉伸到与容器相同的高度或宽度。<br/>- flex-start:元素向交叉轴起点对齐。<br/>- flex-end:元素向交叉轴终点对齐。<br/>- center:元素在交叉轴居中。<br/>align-items样式作用在每一列的子元素上,列与列之间采用均分方式布局。 | 54e41f4b71Sopenharmony_ci| item-extent | <length> \| <percentage> | - | 否 | 设置内部item为固定大小,设置为百分比格式时,指相对于list的视口主轴方向长度的百分比。 | 55e41f4b71Sopenharmony_ci| fade-color | <color> | grey | 否 | 设置渐隐物理动效的颜色。当滑动效果设置为渐隐物理动效时生效。 | 56e41f4b71Sopenharmony_ci| scrollbar-color<sup>6+</sup> | <color> | - | 否 | 设置滚动条的颜色。 | 57e41f4b71Sopenharmony_ci| scrollbar-width<sup>6+</sup> | <length> | - | 否 | 设置滚动条的宽度。 | 58e41f4b71Sopenharmony_ci| scrollbar-offset<sup>6+</sup> | <length> | 0 | 否 | 设置滚动条距离List默认位置的偏移量,只支持正数,默认位置在List右边缘,可以通过这个偏移量调整滚动条的水平位置,如果滚动条绘制在list外部,而list父组件有裁剪,会导致滚动条被裁剪。 | 59e41f4b71Sopenharmony_ci 60e41f4b71Sopenharmony_ci 61e41f4b71Sopenharmony_ci## 事件 62e41f4b71Sopenharmony_ci 63e41f4b71Sopenharmony_ci除支持[通用事件](js-components-common-events.md)外,还支持如下事件: 64e41f4b71Sopenharmony_ci 65e41f4b71Sopenharmony_ci| 名称 | 参数 | 描述 | 66e41f4b71Sopenharmony_ci| -------------------------- | ------------------------------------------------------------ | ------------------------------------------------------------ | 67e41f4b71Sopenharmony_ci| indexerchange<sup>5+</sup> | { local: booleanValue } | 多语言索引条切换事件,仅当indexer属性为true,indexermulti为true时生效。booleanValue可能值为true或者false:<br/>- true: 当前展示本地索引。<br/>- false: 当前展示字母索引。 | 68e41f4b71Sopenharmony_ci| scroll | { scrollX: scrollXValue, scrollY: scrollYValue, scrollState: stateValue } | 列表滑动的偏移量和状态回调。<br/>stateValue: 0表示列表滑动已经停止。<br/>stateValue: 1表示列表正在用户触摸状态下滑动。<br/>stateValue: 2表示列表正在用户松手状态下滑动。 | 69e41f4b71Sopenharmony_ci| scrollbottom | - | 当前列表已滑动到底部位置。 | 70e41f4b71Sopenharmony_ci| scrolltop | - | 当前列表已滑动到顶部位置。 | 71e41f4b71Sopenharmony_ci| scrollend | - | 列表滑动已经结束。 | 72e41f4b71Sopenharmony_ci| scrolltouchup | - | 手指已经抬起且列表仍在惯性滑动。 | 73e41f4b71Sopenharmony_ci| requestitem | - | 请求创建新的list-item。<br/>长列表延迟加载时,可视区域外缓存的list-item数量少于cachedcount时,会触发该事件。 | 74e41f4b71Sopenharmony_ci| rotation<sup>7+</sup> | { rotateValue: number } | 返回表冠旋转角度增量值,仅智能穿戴支持。 | 75e41f4b71Sopenharmony_ci 76e41f4b71Sopenharmony_ci 77e41f4b71Sopenharmony_ci## 方法 78e41f4b71Sopenharmony_ci 79e41f4b71Sopenharmony_ci支持[通用方法](js-components-common-methods.md)外,还支持如下方法: 80e41f4b71Sopenharmony_ci 81e41f4b71Sopenharmony_ci| 名称 | 参数 | 描述 | 82e41f4b71Sopenharmony_ci| ------------- | ---------------------------------------- | ---------------------------------------- | 83e41f4b71Sopenharmony_ci| scrollTo | { index: number(指定位置) } | list滑动到指定index的item位置。 | 84e41f4b71Sopenharmony_ci| scrollTop | { smooth: boolean } | smooth缺省为false,表示直接滚动到顶部。<br/>smooth为true,表示平滑滚动到顶部。 | 85e41f4b71Sopenharmony_ci| scrollBottom | { smooth: boolean } | smooth缺省为false,表示直接滚动到底部。<br/>smooth为true,表示平滑滚动到底部。 | 86e41f4b71Sopenharmony_ci| scrollPage | { reverse: boolean, smooth: boolean } | reverse缺省值为false,表示下一页,无完整页则滚动到底部。<br/>reverse为true,表示上一页,无完整页则滚动到顶部。<br/>smooth缺省值为false,表示直接滚动一页。<br/>smooth为true,表示平滑滚动一页。 | 87e41f4b71Sopenharmony_ci| scrollArrow | { reverse: boolean, smooth: boolean } | reverse缺省值为false,表示向底部方向滑动一段距离,无足够距离则滚动到底部。<br/>reverse为true,表示向顶部方向滑动一段距离,无足够距离则滚动到顶部。<br/>smooth缺省值为false,表示直接滚动。<br/>smooth为true,表示平滑滚动。 | 88e41f4b71Sopenharmony_ci| collapseGroup | { groupid: string } | 收拢指定的group。<br/>groupid:需要收拢的group的id。<br/>当groupid未指定时收拢所有的group。 | 89e41f4b71Sopenharmony_ci| expandGroup | { groupid: string } | 展开指定的group。<br/>groupid:需要展开的group的id。<br/>当groupid未指定时展开所有的group。 | 90e41f4b71Sopenharmony_ci| currentOffset | - | 返回当前滑动的偏移量。返回值类型是Object,返回值说明请见表 currentOffset返回对象属性说明。 | 91e41f4b71Sopenharmony_ci 92e41f4b71Sopenharmony_ci**表1** currentOffset返回对象属性说明 93e41f4b71Sopenharmony_ci 94e41f4b71Sopenharmony_ci| 名称 | 类型 | 备注 | 95e41f4b71Sopenharmony_ci| ---- | ------ | ---------------- | 96e41f4b71Sopenharmony_ci| x | number | 当前x轴滑动偏移量,单位为px。 | 97e41f4b71Sopenharmony_ci| y | number | 当前y轴滑动偏移量,单位为px。 | 98e41f4b71Sopenharmony_ci 99e41f4b71Sopenharmony_ci## 示例 100e41f4b71Sopenharmony_ci 101e41f4b71Sopenharmony_ci```html 102e41f4b71Sopenharmony_ci<!-- index.hml --> 103e41f4b71Sopenharmony_ci<div class="container"> 104e41f4b71Sopenharmony_ci <list class="todo-wrapper"> 105e41f4b71Sopenharmony_ci <list-item for="{{todolist}}" class="todo-item"> 106e41f4b71Sopenharmony_ci <div style="flex-direction: column;align-items: center;justify-content: center;"> 107e41f4b71Sopenharmony_ci <text class="todo-title">{{$item.title}}</text> 108e41f4b71Sopenharmony_ci <text class="todo-title">{{$item.date}}</text> 109e41f4b71Sopenharmony_ci </div> 110e41f4b71Sopenharmony_ci </list-item> 111e41f4b71Sopenharmony_ci </list> 112e41f4b71Sopenharmony_ci</div> 113e41f4b71Sopenharmony_ci``` 114e41f4b71Sopenharmony_ci```css 115e41f4b71Sopenharmony_ci/* index.css */ 116e41f4b71Sopenharmony_ci.container { 117e41f4b71Sopenharmony_ci display: flex; 118e41f4b71Sopenharmony_ci justify-content: center; 119e41f4b71Sopenharmony_ci align-items: center; 120e41f4b71Sopenharmony_ci width: 100%; 121e41f4b71Sopenharmony_ci height: 100%; 122e41f4b71Sopenharmony_ci} 123e41f4b71Sopenharmony_ci.todo-wrapper { 124e41f4b71Sopenharmony_ci width: 100%; 125e41f4b71Sopenharmony_ci height: 300px; 126e41f4b71Sopenharmony_ci} 127e41f4b71Sopenharmony_ci.todo-item { 128e41f4b71Sopenharmony_ci width: 100%; 129e41f4b71Sopenharmony_ci height: 120px; 130e41f4b71Sopenharmony_ci justify-content:center; 131e41f4b71Sopenharmony_ci} 132e41f4b71Sopenharmony_ci.todo-title { 133e41f4b71Sopenharmony_ci width: 100%; 134e41f4b71Sopenharmony_ci height: 80px; 135e41f4b71Sopenharmony_ci text-align: center; 136e41f4b71Sopenharmony_ci} 137e41f4b71Sopenharmony_ci``` 138e41f4b71Sopenharmony_ci 139e41f4b71Sopenharmony_ci```js 140e41f4b71Sopenharmony_ci// index.js 141e41f4b71Sopenharmony_ciexport default { 142e41f4b71Sopenharmony_ci data: { 143e41f4b71Sopenharmony_ci todolist: [{ 144e41f4b71Sopenharmony_ci title: '刷题', 145e41f4b71Sopenharmony_ci date: '2021-12-31 10:00:00' 146e41f4b71Sopenharmony_ci }, { 147e41f4b71Sopenharmony_ci title: '看电影', 148e41f4b71Sopenharmony_ci date: '2021-12-31 20:00:00' 149e41f4b71Sopenharmony_ci }], 150e41f4b71Sopenharmony_ci }, 151e41f4b71Sopenharmony_ci} 152e41f4b71Sopenharmony_ci``` 153e41f4b71Sopenharmony_ci 154e41f4b71Sopenharmony_ci 155e41f4b71Sopenharmony_ci 156e41f4b71Sopenharmony_ci 157