返回顶部
首页 > 资讯 > 前端开发 > JavaScript >微信小程序实现字母索引菜单
  • 380
分享到

微信小程序实现字母索引菜单

2024-04-02 19:04:59 380人浏览 薄情痞子
摘要

本文实例为大家分享了微信小程序实现字母索引菜单的具体代码,供大家参考,具体内容如下 wxml文件 <view class="container"> <view c

本文实例为大家分享了微信小程序实现字母索引菜单的具体代码,供大家参考,具体内容如下

wxml文件

<view class="container">

<view class="content">
  <view class="all-food">
    <view class="food">全部食物</view>
      <scroll-view class="food-scroll" scroll-y="true" scroll-into-view="{{toView}}" scroll-with-animation="true">
        <view class="food-list">

            <view wx:for="{{foodList}}" wx:key="{{index}}" id="{{'food'+index}}"  data-title="{{item.title}}">
              <view class="nav-text">
                <text>{{item.title}}</text>
              </view>
              <view class="show-food">
                <text wx:for="{{item.lists}}" wx:key="{{index}}">{{item}}</text>
              </view>
            </view>

        </view>
      </scroll-view>
    </view>

  <view class="search-nav"  bindtouchstart="touchStart" bindtouchmove="touchMove" bindtouchend="touchEnd">
    <text bindtap="foodScroll" data-index="{{index}}" wx:for="{{searchNav}}" wx:key="{{index}}">{{item}}</text>
  </view>
</view>
</view>

js文件

let foodList = require('../../utils/common');
Page({

  
  data: {
    foodList:[],
    toView:'',
    searchNav:[]
  },

  getFoodList(){
        let searchNav = this.data.searchNav
        for(let i in foodList.foodList){
            searchNav.push(foodList.foodList[i].title)
        }
        this.setData({
            foodList:foodList.foodList,
            searchNav:searchNav
        })

  },
  
  foodScroll(e){
        let index = e.currentTarget.dataset.index;
        this.setData({
            toView:`food${index}`
        })

    },
  
  onLoad: function (options) {
    this.getFoodList();
  },

  
  onReady: function () {
    
  },

  
  onShow: function () {
    
  },

  
  onHide: function () {
    
  },

  
  onUnload: function () {
    
  },

  
  onPullDownRefresh: function () {
    
  },

  
  onReachBottom: function () {
    
  },

  
  onShareAppMessage: function () {
    
  }
})

wxss文件

 
 .container {
  padding: 0 5rpx;
  display: flex;
  justify-content:row;
  background-color: #fff;
}

.content{
  margin-top: 30rpx;
  width: 100%;
}

.food{
  font-size: 40rpx;
  padding-bottom: 10rpx;
  border-bottom: 1rpx solid #fff;
  height:30rpx;
  line-height:30rpx;

}

.food-scroll {
  left: 0;
  position: fixed;
  height: 100%;
  width: 720rpx;
}

.show-food{
  display: flex;
  flex-direction: column;
  justify-content: left;
  
}
.show-food text{
  margin-top: 10rpx;
  margin-bottom: 10rpx;
  font-size: 32rpx;
  border-bottom: 1rpx solid silver;
}

.search-nav{
  position: fixed;
  top: 120rpx;
  bottom: 5rpx;
  right: 5rpx;
  display:flex;
  flex-direction: column;
  justify-content: space-around;
}
.search-nav text{
  text-align: center;
  font-size: 24rpx;
}

common.js文件

let food = [     
  {
      "title":"A",
      "lists":[
      "艾蒿"
        ]
  },
  {
      "title":"B",
      "lists":["白萝卜","白瓜","白菜","菠菜","白笋","百合","摈榔","白花菜","白沙蒿","百里香","豆腐柴","芭蕉","菠萝","白金瓜"
        ]
  },
  {
      "title":"C",
      "lists":["蚕豆","菜花","春笋","慈菇","刺儿菜","草菇","草莓","橙","茶肠","草鱼","鲳鱼"
        ]
  },
  {
      "title":"D",
      "lists":["豆腐","豆浆","豆腐脑","豆奶","豆汁","豆腐丝","豆腐卷","豆腐皮","豆腐干","豆干尖","豆沙","刀豆","豆角","冬瓜","大蒜","大葱","大白菜","冬寒菜","冬笋","豆瓣菜","大薯","大车前","地肤","大黄","大麻","大红菇","地衣","蛋清肠"
        ]
  },
  {
      "title":"E",
      "lists":["鹅肉","鹅肝","鹅腿","鹅蛋"]
  },
  {
      "title":"F",
      "lists":["粉丝","腐竹","番茄","方瓜","佛手瓜","分葱","发菜"
        ]
      
  },
  {
     "title":"G",
      "lists":["挂面","甘薯","甘蓝","观达菜","枸杞","柑","桂圆","橄榄","桂鱼","鲑鱼"]
     
  },
  {
     "title":"H",
      "lists":["花卷","黄豆","花豆","红萝卜","花叶萝卜","胡萝卜","荷兰豆","黄豆芽","葫子","葫芦","葫芦条","黄瓜","茴香","黑笋","花案菜","槐花","黄麻叶","苦苦菜","猴头菇","黄菇","海带","海棠","黄皮果","火腿肠","火鸡","火鸡肝","火鸡腿","黄油","黄鳝","鳇鱼","黄骨鱼"
       ]
  },
  {
     "title":"J",
      "lists":["豇豆","芥菜头","节瓜","金瓜","金丝瓜","韭菜","韭黄","韭苔","金针菜","菊笋","茭白","姜","蕨菜","金针菇","鸡肉","鸡腿","鸡心","鸡翅","鸡肾","鸡脖"]
           
  },
  {
     "title":"K",
      "lists":["空锅饼","苦瓜","苦菜","口蘑","葵花籽"]

  },
  {
     "title":"L",
      "lists":["烙饼","绿豆饼","龙豆","绿豆芽","辣椒","萝卜缨","落葵","轮叶党参","罗勒","梨","梅","荔枝","栗子","腊肉","驴肉","驴鞭","驴心","骆驼肉","骆驼掌","骆驼蹄", ]

  },
  {
      "title":"M",
      "lists":["面条","馒头","木薯","梅豆","木豆","毛豆","毛笋","马蹄","马齿苋","马兰头","麦瓶草",
      "蘑菇","木耳","面蛋","芒果","木瓜","马肉","马心"
  ]
  },
  {
     "title":"N",
      "lists":["脑豆","奶茄子","南瓜","牛至","柠檬","牛肉","牛肋","牛腿","牛里脊","牛蹄筋", "牛鞭","牛肚","牛肝","牛肺","牛脑","牛骨","牛大肠","牛心","牛肾","牛肉干", "牛肉松",
                    ]
  },
  {
   "title":"O",
      "lists":["藕粉","藕"]
  },
  {
     "title":"P",
      "lists":["扁豆","蒲菜","喷瓜","蒲公英","苹果","葡萄","葡萄干"]

  },
  {
     "title":"Q",
      "lists":["荞麦","青豆","茄子","秋葵","青蒜","芹菜","掐不齐","清明菜","球茎茴香","启明菜叶","青菇"
  ]
  },
  {
     "title":"R",
      "lists":["人参果","肉松","儿童肠"]
  },
  {
     "title":"S",
      "lists":["烧饼","水面筋","马铃薯","素火腿","素大肠","素鸡","素鸡丝卷","素什锦","四季豆","蛇瓜","丝瓜","笋瓜","蒜苗","生菜","水芹菜","山药","石头菜","沙参叶","松菇","沙果","酸刺","石榴","柿子","柿饼","桑葚"
       ]
           
  },
  {
     "title":"T",
      "lists":["通心面","甜椒","甜菜叶","茼蒿","汤菜","土三七","苔菜","桃","甜瓜","兔肉"
       ]
  },
  {
   "title":"W",
   "lists":["豌豆","乌菜","莴笋","歪头菜","梧桐子","无花果","午餐肉"
    ]
  },
  {
     "title":"X",
      "lists":["小豆粥","西葫芦","小葱","小白菜","西兰花","香菜","苋菜","夏枯草","香椿","香茅","小旋花","竹叶菜","香菇","香蕉","西瓜","杏仁","橡子","叉烧肉","咸肉","香肠"
       ]
           
  },
  {
     "title":"Y",
      "lists":["油饼","油条","油面筋","薏米","玉米","芸豆","洋葱","油菜","芋头","洋姜","野葱","野韭菜","营野菊口","野蒜","野苋菜","榆钱","鱼腥草","羊肚菌","银耳","樱桃","柚","杨梅"
       ]
     
  },
  {
      "title":"Z",
      "lists":["竹笋"," 榛子","珍珠白菇","紫菜","枣","猪肉","芝麻","猪大排","猪耳","猪蹄","猪头","猪肘","猪肺","猪肝","猪脑","猪皮","猪舌","猪腰","猪心","猪血"
       ]
  }
   ]
module.exports = {
   foodList:food
}

目录文件

效果

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持编程网。

--结束END--

本文标题: 微信小程序实现字母索引菜单

本文链接: https://lsjlt.com/news/164412.html(转载时请注明来源链接)

有问题或投稿请发送至: 邮箱/279061341@qq.com    QQ/279061341

猜你喜欢
  • 微信小程序实现字母索引菜单
    本文实例为大家分享了微信小程序实现字母索引菜单的具体代码,供大家参考,具体内容如下 wxml文件 <view class="container"> <view c...
    99+
    2024-04-02
  • 微信小程序如何实现字母索引菜单
    本篇内容介绍了“微信小程序如何实现字母索引菜单”的有关知识,在实际案例的操作过程中,不少人都会遇到这样的困境,接下来就让小编带领大家学习一下如何处理这些情况吧!希望大家仔细阅读,能够学有所成!wxml文件<view clas...
    99+
    2023-07-02
  • 微信小程序实现联动菜单
    最近为了实现课程设计,也做了一些前端的东西,今天想要做一个联动菜单来实现一些功能。实现了,也来做做笔记。 第1步:了解一下 左右侧菜单其实简单来讲就是把一个区域分成左右两个部分。关于...
    99+
    2024-04-02
  • 微信小程序实现收缩式菜单
    本文实例为大家分享了微信小程序实现收缩式菜单的具体代码,供大家参考,具体内容如下 wxml文件 <view class="page"> <!--分类 -->...
    99+
    2024-04-02
  • 微信小程序实现简单搜索框
    本文实例为大家分享了微信小程序实现简单搜索框的具体代码,供大家参考,具体内容如下 app.json {   "pages":[     "pages/index/index"   ]...
    99+
    2024-04-02
  • 微信小程序实现点餐小程序左侧滑动菜单
    目录前言一、初识scroll-view二、左侧导航三、右侧滑动前言 最近在帮亲戚做一款微信的点餐小程序,以前从没有接触过小程序的我只能现做现卖。一边看文档一边实践尝试,在进行到点菜模...
    99+
    2024-04-02
  • 微信小程序如何实现收缩式菜单
    这篇“微信小程序如何实现收缩式菜单”文章的知识点大部分人都不太理解,所以小编给大家总结了以下内容,内容详细,步骤清晰,具有一定的借鉴价值,希望大家阅读完这篇文章能有所收获,下面我们一起来看看这篇“微信小程序如何实现收缩式菜单”文章吧。wxm...
    99+
    2023-07-02
  • 微信小程序实现双层嵌套菜单栏
    最近在做的项目有这样一个需求,也不太好描述,就是有两个顶部菜单栏,每个二级菜单栏的item都有自己页面,每个页面都可以通过左右滑动来切换,第一个想到的实现方法就是双层swiper嵌套...
    99+
    2024-04-02
  • 小程序自定义索引菜单
    本文实例为大家分享了小程序自定义索引菜单的具体代码,供大家参考,具体内容如下 <view class="indexes_chunk" wx:for="{{brandIndex...
    99+
    2024-04-02
  • 微信小程序实现简单搜索功能
    本文实例为大家分享了微信小程序实现简单搜索功能的具体代码,供大家参考,具体内容如下 搜索效果图 实现功能如下 (1) 未找到商品时显示提示信息,找到商品时显示商品列表 (2) 清空...
    99+
    2024-04-02
  • 微信小程序实现多层级复选框菜单
    目录一、背景二 、效果展示三、功能点四、代码实现五 、最后本文实例为大家分享了微信小程序自定义多层级复选框菜单的具体代码,供大家参考,具体内容如下 一、背景 因客户需要,有一个功能是...
    99+
    2024-04-02
  • 微信小程序实现菜单左右联动效果
    本文实例为大家分享了微信小程序实现菜单左右联动效果的具体代码,供大家参考,具体内容如下 原理 首先是获取数据,并且获取数据的长度(需要根据长度来计算元素的高度),通过遍历数据的内容通...
    99+
    2024-04-02
  • 实现微信小程序中的下拉菜单效果
    实现微信小程序中的下拉菜单效果,需要具体代码示例随着移动互联网的普及,微信小程序成为了互联网开发的重要一环,越来越多的人开始关注和使用微信小程序。微信小程序的开发相比传统的APP开发更加简便快捷,但也需要掌握一定的开发技巧。在微信小程序的开...
    99+
    2023-11-21
    下拉菜单 微信小程序 实现
  • 使用微信小程序实现滑动菜单效果
    使用微信小程序实现滑动菜单效果微信小程序作为一种快速开发并具有广泛应用的工具,为我们提供了多种实现滑动菜单效果的方法。本文将向您展示一种简单而实用的实现方式,帮助您在开发中轻松添加滑动菜单效果。准备工作在开始编码之前,我们需要先创建一个基本...
    99+
    2023-11-21
    微信小程序 实现 滑动菜单
  • 微信小程序如何实现点餐小程序左侧滑动菜单
    这篇文章主要讲解了“微信小程序如何实现点餐小程序左侧滑动菜单”,文中的讲解内容简单清晰,易于学习与理解,下面请大家跟着小编的思路慢慢深入,一起来研究和学习“微信小程序如何实现点餐小程序左侧滑动菜单”吧!效果图:一、初识scroll-view...
    99+
    2023-07-02
  • 微信小程序如何实现双层嵌套菜单栏
    这篇文章主要介绍“微信小程序如何实现双层嵌套菜单栏”,在日常操作中,相信很多人在微信小程序如何实现双层嵌套菜单栏问题上存在疑惑,小编查阅了各式资料,整理出简单好用的操作方法,希望对大家解答”微信小程序如何实现双层嵌套菜单栏”的疑惑有所帮助!...
    99+
    2023-07-02
  • 小程序如何自定义索引菜单
    本文小编为大家详细介绍“小程序如何自定义索引菜单”,内容详细,步骤清晰,细节处理妥当,希望这篇“小程序如何自定义索引菜单”文章能帮助大家解决疑惑,下面跟着小编的思路慢慢深入,一起来学习新知识吧。<view class=&qu...
    99+
    2023-07-02
  • 微信公众号菜单如何配置微信小程序
    这篇文章给大家分享的是有关微信公众号菜单如何配置微信小程序的内容。小编觉得挺实用的,因此分享给大家做个参考,一起跟随小编过来看看吧。先提条件是你的公众号版定了小程序第一种:直接配置   ...
    99+
    2024-04-02
  • 微信小程序如何实现上拉、下拉菜单功能
    这篇文章给大家分享的是有关微信小程序如何实现上拉、下拉菜单功能的内容。小编觉得挺实用的,因此分享给大家做个参考,一起跟随小编过来看看吧。解决方案上下拉菜单在微信小程序中起提示、选项的功能,当点击它时会弹出属...
    99+
    2024-04-02
  • 微信小程序中如何实现仿美团分类菜单
    这篇文章将为大家详细讲解有关微信小程序中如何实现仿美团分类菜单,小编觉得挺实用的,因此分享给大家做个参考,希望大家阅读完这篇文章后可以有所收获。有同学要仿美团分类菜单.写了一个跟 微信小程序开发之实现选项卡...
    99+
    2024-04-02
软考高级职称资格查询
编程网,编程工程师的家园,是目前国内优秀的开源技术社区之一,形成了由开源软件库、代码分享、资讯、协作翻译、讨论区和博客等几大频道内容,为IT开发者提供了一个发现、使用、并交流开源技术的平台。
  • 官方手机版

  • 微信公众号

  • 商务合作