Index 索引选择器

概述

常用于通讯录、城市选择的索引选择器。

使用指南

在 .json 中引入组件

  1. "usingComponents": {
  2. "i-index": "../../dist/index/index",
  3. "i-index-item": "../../dist/index-item/index"
  4. }

示例

  1. <view class="i-index-demo">
  2. <i-index height="100%" bind:change="onChange">
  3. <i-index-item
  4. wx:for="{{ cities }}"
  5. wx:for-index="index"
  6. wx:key="{{index}}"
  7. wx:for-item="item" name="{{item.key}}">
  8. <view
  9. class="i-index-demo-item"
  10. wx:for="{{item.list}}"
  11. wx:for-index="in"
  12. wx:key="{{in}}"
  13. wx:for-item="it">
  14. {{it.name}}
  15. </view>
  16. </i-index-item>
  17. </i-index>
  18. </view>
  1. import { cities } from './city';
  2. Page({
  3. data : {
  4. cities : []
  5. },
  6. onChange(event){
  7. console.log(event.detail,'click right menu callback data')
  8. },
  9. onReady(){
  10. let storeCity = new Array(26);
  11. const words = ["A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"]
  12. words.forEach((item,index)=>{
  13. storeCity[index] = {
  14. key : item,
  15. list : []
  16. }
  17. })
  18. cities.forEach((item)=>{
  19. let firstName = item.pinyin.substring(0,1);
  20. let index = words.indexOf( firstName );
  21. storeCity[index].list.push({
  22. name : item.name,
  23. key : firstName
  24. });
  25. })
  26. this.data.cities = storeCity;
  27. this.setData({
  28. cities : this.data.cities
  29. })
  30. }
  31. });

API

Index properties

属性说明类型默认值
i-class自定义 class 类名String-
height容器 scroll-view 的高度,支持各种单位String300
item-height选择项的高度,单位 pxNumber18

Index events

事件名说明返回值
bind:change选择项改变时触发,{index, current}

IndexItem properties

属性说明类型默认值
i-class自定义 class 类名String-
name选择项的标题String-