微信小程序之使用wx:for遍历循环
效果图如下:

实现代码如下:
type.js:
// pages/type/type.js
Page({ /**
* 页面的初始数据
*/
data: {
types: ""
},
editType: function (e) {
var typeId = e.currentTarget.dataset['id'];
console.log("edit:"+typeId); wx.navigateTo({
url: '../type_edit/type_edit?typeId=' + typeId
})
},
delType:function(e){ var typeId = e.currentTarget.dataset['id']; console.log("delete:"+typeId) wx.showModal({
title: '提示',
content: '确认要删除该支出类型?',
success: function (res) {
if (res.confirm) {
console.log('用户点击确定') wx.request({ url: getApp().globalData.urlPath + "spendingType/delete",
method: "POST",
data: {
typeId: typeId
},
header: {
"Content-Type": "application/x-www-form-urlencoded"
},
success: function (res) {
console.log(res.data.code);
if (res.statusCode == ) { //访问正常
if (res.data.code == "") {
wx.showToast({
title: "删除成功,返回支出类型列表",
icon: 'success',
duration: ,
success: function () { wx.navigateTo({
url: '../type/type'
})
}
}) }
} else { wx.showLoading({
title: '系统异常',
fail
}) setTimeout(function () {
wx.hideLoading()
}, )
} }
}) } else if (res.cancel) {
console.log('用户点击取消')
}
}
}) },
/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
wx.setNavigationBarTitle({ title: "支出类型列表" })
var userCode = wx.getStorageSync('userId');
var self = this
wx.request({
url: getApp().globalData.urlPath + "spendingType/types",//json数据地址
data: {
userCode: userCode
},
headers: {
"Content-Type": "application/x-www-form-urlencoded"
},
success: function (res) {
self.setData({ types: res.data.data });//等同于 }
})
}, /**
* 生命周期函数--监听页面初次渲染完成
*/
onReady: function () { }, /**
* 生命周期函数--监听页面显示
*/
onShow: function () { }, /**
* 生命周期函数--监听页面隐藏
*/
onHide: function () { }, /**
* 生命周期函数--监听页面卸载
*/
onUnload: function () { }, /**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh: function () { }, /**
* 页面上拉触底事件的处理函数
*/
onReachBottom: function () { }, /**
* 用户点击右上角分享
*/
onShareAppMessage: function () { }
})
type.js没什么好说的,如果要说,只能说这个onLoad这里的onLoad就相当于js中的onload方法,当进入该视图时,默认全局加载一次。
type.wxml:
<view>
<view>
<navigator url="/pages/type_add/type_add" hover-class="navigator-hover">添加支出类型信息</navigator>
</view>
<view>
<text>\n</text>
</view>
<view>
<view>
<text>列表数据</text>
<text>\n</text>
</view>
<view class="table">
<view class="tr thead">
<view class="td">类型名</view>
<view class="td">创建时间</view>
<view class="td ">修改时间</view>
<view class="td">备注</view>
<view class="td ">操作</view>
</view>
<block>
<view class="tr" wx:for="{{types}}" wx:for-item="item">
<view class="td">{{item.typeName}}</view>
<view class="td">{{item.createDate}}</view>
<view class="td">{{item.modifyDate}}</view>
<view class="td">{{item.remark}}</view>
<view class="td">
<text bindtap='editType' data-id="{{item.typeId}}">编辑</text>
<text>\n</text>
<text>\n</text>
<text bindtap='delType' data-id="{{item.typeId}}">删除</text>
</view>
</view>
</block>
</view> </view>
</view>
遍历循环主要使用的是wx:for。如果要类比的话,我觉得jstl跟这个神似。先来看看jstl,代码如下:
<c:forEach var="u" items="${user}">
<tr>
<td>${u.cid}</td>
<td>${u.cname}</td>
<td>${u.age }</td>
</tr>
</c:forEach>
var相当于我可以任意定义一个简要字母来调用item(item相当于type.js中的data或self.setData存储的数据)。
如果你还不明白的话,可以联系到$.each,代码如下:
$.each(classroom_list, function(i, c) {
rows = rows + "<tr>";
rows = rows + "<td>" + c.id + "</td>";
rows = rows + "<td>" + c.nickname + "</td>";
rows = rows + "<td><a href='student_submit_info.html?userId="+c.id+"'>查看详情</a></td>";
rows = rows + "</tr>"
});
type.wxss:
.table {
border: 1px solid #ccc;
font-size: 28rpx;
background: #fff;
border-right: none;
}
.tr{
display: flex;
justify-content: space-between;
}
.td {
text-align: center;
border: 1px solid #ccc;
display: inline-block;
border-left: none;
border-bottom: none;
padding: 10rpx %;
width: %;
}
.thead .td{
border-top: none;
height: 140rpx;
line-height: 50rpx;
}
参考资料:
微信小程序之列表渲染
微信小程序之使用wx:for遍历循环的更多相关文章
- 微信小程序中在swiper-item中遍历循环添加多个数据内容(微信小程序交流群:604788754)
在小程序中为了实现一个<swiper-item>中添加多个内容重复的标签,那就需要使用wx:for循环.如果按小程序的简易教程,循环加在block中,而swiper-item放在里面.所有 ...
- 【微信小程序】调用wx.request接口需要注意的问题
写在前面 之前写了一篇<微信小程序实现各种特效实例>,上次的小程序的项目我负责大部分前端后台接口的对接,然后学长帮我改了一些问题.总的来说,收获了不少吧! 现在项目已经完成,还是要陆陆续续 ...
- 开发 | 微信小程序API-wx.setScreenBrightness/wx.getScreenBrightness
前言 最近接触了微信小程序 API - wx.setScreenBrightness .wx.getScreenBrightness 接口,调用该接口可以调节并显示手机屏幕亮度数据.对于喜欢腾讯新闻. ...
- 关于微信小程序遇到的wx.request({})问题
域名请求错误问题 当我们在编写小程序,要发送请求时,wx.request({})时或许会遇到如下的问题: 一:这是因为微信小程序的开发中,域名只能是https方式请求,所以我们必须在小程序微信公众平台 ...
- 微信小程序开发 [05] wx.request发送请求和妹纸图
1.wx.request 微信小程序中用于发起网络请求的API就是wx.request了,具体的参数太多,此处就不再一一详举了,基本使用示例如下: wx.request({ url: 'test.ph ...
- 微信小程序web-view之wx.miniProgram.redirectTo
17年微信小程序官方提供了web-view组件. 官方描述:web-view组件是一个可以用来承载网页的容器,会自动铺满整个小程序页面.个人类型与海外类型的小程序暂不支持使用. 这段时间研究了一下小程 ...
- 微信小程序网络请求wx.request请求
最近微信小程序开始开放测试了,小程序提供了很多api,极大的方便了开发者,其中网络请求api是wx.request(object),这是小程序与开发者的服务器实现数据交互的一个很重要的api. 百牛信 ...
- 一,前端---关于微信小程序遇到的wx.request({})问题
域名请求错误问题 当我们在编写小程序,要发送请求时,wx.request({})时或许会遇到如下的问题: 一:这是因为微信小程序的开发中,域名只能是https方式请求,所以我们必须在小程序微信公众平台 ...
- 微信小程序:使用wx.request()请求后台接收不到参数
问题描述: 微信小程序:wx.request()请求后台接收不到参数,我通过wx.request()使用POST方式调用请求,参数传递不到后台 解决方案: Content-Type': 'applic ...
随机推荐
- Django:信号的使用
信号 Django中提供了"信号调度",用于在框架执行操作时解耦.通俗来讲,就是一些动作发生的时候,信号允许特定的发送者去提醒一些接受者. 应用:比如插入数据到数据库,插入之前写日 ...
- Mysql 库表操作初识
Mysql 库表操作初识 终端登录mysql 这里只演示win下, cmd 终端. 至于怎么在win下, linux, mac安装, 感觉这是一个入门级的百度搜索问题, 安装都搞不定, 确实有点尴尬, ...
- docker启动报错解决及分析(Cannot create container for service *******: cannot mount volume over existing file, file exists /var/lib/docker/overlay2/)
现象: Cannot create container for service *******: cannot mount volume over existing file, file exists ...
- QuickStart系列:docker部署之Gitlab本地代码仓库
gitlab是可以在本地搭建的使用git作为源代码管理的仓库. 运行环境: win10+vmware14+docker7+docker 1. 使用命令拉取镜像(非必须,耗时比较久,这里以ce为准,ce ...
- 安装python工具
安装python编写工具 本篇幅只限于安装linux系统上. 想要实现linux程序在windows桌面上打开,需要在linux上打开X11forward和在windows上安装Xmanager ID ...
- Pthon面向对象-补充知识
Pthon面向对象-补充知识 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.tracemalloc 标准库tracemalloc,可以统计内存使用情况,通过下面的案例可以看出内 ...
- CentOS7怎样安装Redis4.0.12
一.安装 yum -y install tcl安装相关依赖 mkdir /usr/local/redis创建redis安装目录 cd /usr/local/redis 进入redis目录 wget h ...
- HTTP get post 请求实例
package wzh.Http; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStr ...
- C++学习 ---- 系列文章
C++ 第十二课 其它标准C函数 C++ 第十一课 标准c内存函数 C++ 第十课:标准c时间与日期函数 C++ 第九课 标准c数学函数 C++ 第八课 标准c字符和字符串 C++ 第七课 标准 C ...
- strtok在keil中使用小笔记及字符串转换为多个浮点数的方法
在pc上面使用这个字符串函数,是没有问题的,但是我在keil中结合rtos来处理字符串的时候,比如char *s = "1.01313;17.2609;17.4875";那么就只能 ...