微信小程序--列表展示

article/2025/11/6 15:49:00

小知识:

wx:for="{{list}}"用来循环数组。

wx:for-item=‘变量名(随便起)’   它是指定循环数据当前的变量名,可以通过  {{变量名.属性}} 展示数组的元素。

wx:for-index=‘变量名(随便起)’,它是指向当前元素的下标名,可以在其他事件中定义自定义事件(data-xxx='{{变量名}}',,该自定义属性可以在参数e下面打印出来)获取该下标。

 思考:二维甚至多维数组应该如何遍历?

例题: 

列表数据如图所示: 

 

例题采用了scroll-view和swiper组件。代码如下:

new_canteen.js:

// pages/canteen/new_canteen.js
const app = getApp();
Page({/** 页面的初始数据*/data: {navigationSetting:{title:'食堂',height: app.globalData.navBarHeight,paddingTop: app.globalData.statusBarHeight,// backgroundColor:'red',size:'default'},tabList: ['一粟堂', '三清园', '七品居','九华厅'],tabNow: 0, //当前选中的tab标签索引search: "",tradeList: [['从前说','千千万万','千千万万','千千万万','千千万万'],['我记得']], //对应tab显示的商家列表list:[ //搜索后的list内容列表{Name:"一粟堂",arr:[{title: '烧卤家族', sale: 358, rating: 4.9, consumption: 15},{title: '烧卤家族', sale: 518, rating: 4.9, consumption: 35},{title: '烧卤家族', sale: 138, rating: 4.9, consumption: 23},]},{Name:"三清园",arr:[{title: '汉味小吃', sale: 156, rating: 4.9, consumption: 25},{title: '汉味小吃', sale: 324, rating: 4.9, consumption: 17},]},{Name:"七品居",arr:[{title: '古茗', sale: 156, rating: 4.9, consumption: 25},{title: '古茗', sale: 351, rating: 4.9, consumption: 19},{title: '古茗', sale: 324, rating: 4.9, consumption: 17},]},{Name:"九华厅",arr:[{title: '汉味小吃', sale: 156, rating: 4.9, consumption: 25},]}],},selectTab (e) { //切换不同的tabthis.setData({tabNow: e.currentTarget.dataset.id})},handleSwiperChange(e) { //对应改变tabthis.setData({tabNow: e.detail.current})},getContent(e) {console.log("主页:",e)this.setData({search: e.detail})},/*** 生命周期函数--监听页面加载*/onLoad: function (options) {},/*** 生命周期函数--监听页面初次渲染完成*/onReady: function () {},/*** 生命周期函数--监听页面显示*/onShow: function () {},/*** 生命周期函数--监听页面隐藏*/onHide: function () {},/*** 生命周期函数--监听页面卸载*/onUnload: function () {},/*** 页面相关事件处理函数--监听用户下拉动作*/onPullDownRefresh: function () {},/*** 页面上拉触底事件的处理函数*/onReachBottom: function () {},/*** 用户点击右上角分享*/onShareAppMessage: function () {}
})

new_canteen.json:

{"usingComponents": {"navigation":"../../components/navbar/navbar","search": "/components/search/search"},"navigationStyle": "custom","navigationBarTextStyle": "black"
}

new_canteen.wxml:

<!--pages/canteen/new_canteen.wxml-->
<navigation defaultSetting="{{navigationSetting}}"></navigation><!--pages/list/trade_company.wxml-->
<!-- <view class="head flex-row"><view class="head-title">食堂</view>
</view> -->
<scroll-view scroll-y class="container"><view class="container-head"><!--Tab选项卡--><scroll-view scroll-x class="scroll_view" scroll-with-animation="true" enable-flex="true"> <view class="tab"> <view class="tab_item {{ tabNow === index ? 'select' : '' }}" wx:for="{{ tabList }}" data-id="{{ index }}" wx:key="index" bindtap="selectTab"> {{ item }} </view> </view></scroll-view></view><search bind:Searchcontent="getContent" ></search><!--下方内容显示--><swiper class="container-swiper" current="{{tabNow}}" bindchange="handleSwiperChange"><swiper-item wx:for="{{list}}" wx:key="index" ><scroll-view class='container-swiper-sc' enable-flex="true"><view class="mendian-list" style="width: 94%; margin-left: 3%;"><block wx:for="{{ list[tabNow].arr }}" wx:for-item="map"><navigator class="mendian-info" url="../canteen/detail"><image class="thumb" src="../../img/大活.png" pb="100"></image><div class="mendian-text"><div class="title">{{map.title}}</div><view class="qisong-juli flex-between" style="font-size: small;"><image src="../../img/ratingstar.png" mode="aspectFit" style="width: 15px;height: 15px;"></image><text style="margin-left: 5px; color: red; background-color: pink;">{{map.rating}}</text><text style="margin-left: 15px;">月售:{{map.sale}}</text><view>人均消费:{{map.consumption}}元/人</view></view></div></navigator></block></view></scroll-view></swiper-item></swiper></scroll-view>

new_canteen.wxss:

/* pages/canteen/new_canteen.wxss */
page {height: 100%;/*页面高度为屏幕的高度*/
}
.head {position: fixed;height: 13%; width: 100%;color: #333;font-size: 30rpx;font-weight: bold;padding-bottom: 10rpx;box-sizing: border-box;
}
.head-title {position: relative;display: inline-block;height: 100%;
}
.head-title::after {content: '';position: absolute;z-index: 99;width: 15px;height: 15px;margin-left: -15rpx;border-top: 3px solid #333;border-right: 3px solid #333;border-top-right-radius: 100%;transform: rotate(-225deg);left: 50%;bottom: 3px;
}
.container {width: 100%;background-color: #fff;overflow: hidden;/* border-radius: 30rpx 30rpx 0 0; */padding: 0 0;
}
.container-head {width: 100%;box-sizing: border-box;}
.scroll_view {height: 80rpx;border-radius: 50rpx;/* background-color: #eeece4; */white-space: nowrap;/*不换行*/}.scroll_view .tab {/* padding: 0 10rpx; */line-height: 65rpx;display: inline-block;text-align: center;height: 80rpx;vertical-align: top;/*防止高度塌陷*/
}
/*激活当前tab样式*/
.scroll_view .select {/* color: #1067D1; */font-size: larger;font-weight: bold;border-bottom: 18px solid #F6CB48;
} 
.tab .tab_item {height: 70rpx;display: inline-block;line-height: 90rpx;margin: 0 26rpx;padding: 0 20rpx;flex: 1;
}
.container-swiper {height: 100%;display: flex;flex-direction: column;flex-flow: column;
}
.container-swiper-sc {height: 100%;
}
.container-swiper-sc .items {padding: 0 2%;width: 100%;box-sizing: border-box;}.container-swiper-sc .items .item-img {width: 30vw;height: 30vw;margin-right: 2.8%;margin-bottom: 10rpx;flex-shrink: 0;}.container-swiper-sc .items .item-img:nth-child(3n+3) {margin-right: 0;}/* 商家列表展示 */
/*列表展示*/
.mendian-list .mendian-info {display: flex;padding: 8px;margin-top: 16rpx;border-radius: 20px;/* border-bottom: 1px #dedede dashed; */border: 2px solid #A9A9A9;/* background-color: #D7EEFC; */
}
.mendian-list .mendian-info:last-child {/* border-bottom: none; */margin-bottom: 3px;
}
.mendian-list .thumb {width: 70px;height: 70px;flex-shrink: 0;margin-right: 15px;border-radius: 10px;background-color: blue;
}
.mendian-list .mendian-text {flex-grow: 1;flex-shrink: 1;display: flex;justify-content: space-between;flex-flow: column;
}
.mendian-list .title {font-size: 18px;font-weight: 600;/* text-align: center; */color: #484848;margin-top: 5px;
}

小图片:

实现效果: 

效果展示

 


http://chatgpt.dhexx.cn/article/CLJXFtsn.shtml

相关文章

vmware 下 ubuntu 双网卡设置

写在前面&#xff1a; 本文章旨在总结备份、方便以后查询&#xff0c;由于是个人总结&#xff0c;如有不对&#xff0c;欢迎指正&#xff1b;另外&#xff0c;内容大部分来自网络、书籍、和各类手册&#xff0c;如若侵权请告知&#xff0c;马上删帖致歉。 目录 step 1&#xf…

Ubuntu18.04 配置网卡

2019/10/29, Ubuntu Server 18.04 摘要&#xff1a;Ubuntu Server 18.04 采用netplan作为网络配置管理&#xff0c;修改IP使其连上网络&#xff0c;修改替换软件源 修改网卡配置# 首先使用ip a查看当前网卡名称&#xff1a; 可以看到eth0就是我们的网卡名称&#xff0c;这个要…

linux Ubuntu网卡配置,Windows 7下用VirtualBox安装Ubuntu网卡配置

Windows 7下用VirtualBox安装Ubuntu&#xff0c;要求Ubuntu能连上互联网&#xff0c;同时在Ubuntu中配置SSH、FTP、NFS服务&#xff0c;能从Win7进行访问。 此时Linux虚拟机需要两块网卡&#xff0c;一块使用NAT方式(网络地址翻译网络)连接&#xff0c;用于连接互联网&#xff…

Ubuntu 双网卡配置优先级

Ubuntu 双网卡配置优先级 作者&#xff1a;Bright Xu Ubuntu的网卡配置跟CentOS不太一样。 更多请参考&#xff1a;CentOS 双网卡配置优先级 根据业务需要&#xff0c;有时候服务器需要两张网卡&#xff0c;一张用于访问外网&#xff0c;另一种用于连接内网。 如果在安装系统是…

ubuntu配置网卡

第一步&#xff1a;查看网卡信息 输入ifconfig命令查看网卡信息&#xff0c;下图红圈处就是网卡名称。 第二步&#xff1a;配置网卡文件 注意&#xff1a;不同的linux系统&#xff0c;网卡配置文件是不同的&#xff0c;这里ubuntu的网卡配置文件是/etc/network/interfaces。 输…

Ubuntu18.04  网卡配置

Ubuntu18.04 网卡配置 Ubuntu18.04网卡配置&#xff0c;不同于其他Linux网卡配置&#xff0c;Ubuntu18.04采用的是 Netplan ,想要了解具体可查看官网。 1、设置网络为&#xff1a;桥接网卡 2、在宿主电脑上使用管理员输入CMD 命令 ipconfig /all 查看子网掩码&#xff…

ubuntu16.04配置网卡

第一步&#xff1a;查看网卡信息 输入ifconfig命令查看网卡信息&#xff0c;下图红圈处就是网卡名称。 第二步&#xff1a;配置网卡文件 注意&#xff1a;不同的linux系统&#xff0c;网卡配置文件是不同的&#xff0c;这里ubuntu的网卡配置文件是/etc/network/interfaces。 …

Ubuntu配置网卡信息(ip、网关、子网掩码、dns)

目录 一、前言二、配置网卡信息三、注意事项 一、前言 本文介绍了Ubuntu系统下配置网卡的信息&#xff0c;包含网卡的ip地址、网关、子网掩码和dns。   网卡的ip地址可以设置成动态&#xff08;DHCP&#xff09;或静态的&#xff0c;网关和掩码根据实际需求选择是否设置。dns…

idea如何用git更新和提交代码

一、git更新操作 第一步&#xff1a; 在提交项目之前必须先对项目进行更新&#xff0c;此项特别重要&#xff0c;如果不进行更新&#xff0c;别人有项目提交到服务器上&#xff0c;那么你的项目将会提交不上去&#xff0c;使用git解决冲突会比较麻烦&#xff0c;即使你解决了冲…

gitee更新代码库

步骤&#xff1a; 克隆仓库(有则省略此步) git clone https://gitee.com/master_wei/trainticketsale_fork.git 一、同步远程仓库信息 git pull origin master …

Git更新代码到本地

一.首先查看git 远程仓库的地址 git remote -v 二,更新代码本地到仓库两种方式&#xff1a; /方法一 $ git fetch origin master //从远程的origin仓库的master分支下载代码到本地的origin master$ git log -p master.. origin/master//比较本地的仓库和远程参考的区别$ git …

git强制更新本地代码,git pull无法更新本地代码,git pull显示更新成功但是本地并没有拉去到最新的代码

git pull之后看见没有&#xff0c;看见了吧&#xff0c;Already up to date. 操作了N遍&#xff0c;但是当对比本地和远程库之后&#xff0c;发现自己本地的代码根本就不是最新的&#xff0c; 怎么解决&#xff1f; 强制更新&#xff0c;将本地代码更新为仓库里最新的代码&a…

Git如何更新远程仓库代码到本地

1.首先可以暂存本地的修改&#xff0c;如果本地没有修改&#xff0c;则会显示“没有要保存的本地修改” git stash 2.执行命令会找到项目重新拉取代码进行更新&#xff0c;可以看到该程序有更新。 git fetch --all3.执行命令进行更新文件的下载覆盖&#xff0c;下面会列出哪些…

Gitee上传、更新仓库代码

Gitee上传、更新仓库代码 Gitee上传1、进入到Gitee中&#xff0c;并创建该项目的远程仓库。2、进入本地你想要上传的文件目录下&#xff0c;右键单击空白处&#xff0c;点击**Git Bash Here**。3、配置你的用户名和邮箱4、初始化本地仓库5、添加项目目录下所有文件至本地仓库6、…

git命令更新代码

拉取代码&#xff1a; git pull 推本地代码上去&#xff1a; 1、git status 2、git add [filename1] [filename2] 3、git commit [filename1] -m “提交信息说明” 4、git push 回退 1、退回至缓存区的coding回退 git reset [filename1] 2、会退到制定版本 git rese…

如何使用git更新别人的代码

文章目录 如何使用git更新别人的代码问题说明省流问题示例操作步骤总结总结 如何使用git更新别人的代码 问题说明 当自己git clone别人的代码之后&#xff0c;代码一直停留到本地电脑上&#xff0c;而你就跑了一次程序就搁置了。 后来有一天你想再次运行该代码&#xff0c;但…

更新github上的代码

昨晚熬夜写完了“git上传本地项目代码到github”的任务&#xff0c;早上来公司先把早上的工作完成后&#xff0c;抽点时间继续来继续更新文章 更新github上的代码 一、克隆代码 1、把大神的代码clone到本地&#xff0c;或者clone自己github上的代码使用命令 git clone http…

git版本如何更新

Windows中怎么更新git版本 直接在桌面右键&#xff1a;Git Bash Heregit2.17.1版本之前 &#xff1a;git updategit2.17.1版本之后 &#xff1a;git update-git-for-windows

Git 提交代码和更新代码

首先&#xff0c;操作之前一定要看清分支&#xff01;&#xff01; 其次&#xff0c;提交代码之前一定要先更新代码&#xff01;&#xff01; git branch -----查看当前分支 git pull -----更新代码到本地 提交代码&#xff1a; 1、在本地修改相应文…

git更新本地代码

IDEA中Git的更新/提交/还原方法 记录一下在IDEA上怎样将写的代码提交到GitHub远程库&#xff1a; 下面这个图是基本的提交代码的顺序&#xff1a; 1. 将代码Add到stage暂存区 本地修改了代码后&#xff0c;需先将代码add到暂存区&#xff0c;最后才能真正提价到git仓库。 首先…