微信小程序模板中使用循环
来源:互联网 发布:淘宝小号怎样申请 编辑:程序博客网 时间:2024/06/05 14:55
本篇介绍如何在模板里使用循环。
方法一:
template.wxml,该文件内容为:
<template name="msgItem1"><block wx:for="{{product1}}" wx:for-item="item" wx:key="pro"> <view> <text> {{item.index}}: {{item.msg}} </text> <text> Time: {{item.time}} </text> </view> </block></template>
方法二:使用模板:
template.wxml,该文件内容为:
<template name="msgItem"> <view> <text> {{index}}: {{msg}} </text> <text> Time: {{time}} </text> </view></template><template name="msgItem1"><block wx:for="{{product1}}" wx:for-item="item" wx:key="pro"> <template is="msgItem" data="{{...item}}"/></block></template>
index.js的内容为:
Page({ data: { product1: [{ index: 0, msg: 'this is a template', time: '217-09-15' }, { index: 1, msg: 'this is a template', time: '2020-09-15' }, { index: 2, msg: 'this is a template', time: '2018-09-15' },] },})
我们在index.wxml里的内容为:
<import src="../template/template.wxml"/><template is="msgItem1" data="{{product1}}"/>
这里不需要使用扩展运算符展开product1。
阅读全文
0 0
- 微信小程序模板中使用循环
- 微信小程序中template模板使用
- 微信小程序-template模板使用
- 微信小程序模板使用总结
- 微信小程序---for循环使用以及循环中的内容获取
- 程序循环的使用
- 在stm32中使用while循环导致程序卡死
- [Wondgirl] 微信小程序(三)模板的使用
- 微信小程序的模板使用详解
- 微信小程序 template模板的使用
- 微信小程序模板template的使用
- 小程序模板使用
- ThinkPHP 3.2.2 在 模板中 多重循环嵌套中使用 if 判断标签
- 使用empire cms(帝国cms)封面模板时循环子标签模板中[--the.classname--]无法更新的问题
- SQL SERVER中FOR循环的模板
- arttemplate使用子模板实现嵌套循环
- 微信小程序实现循环列表中加样式
- 微信小程序遍历循环中点击添加样式
- Please change caller according to com.intellij.openapi.project.IndexNotReadyException documentation
- SourceTree 使用手册(第一篇)
- JAVA中ListIterator和Iterator详解与辨析
- 下三角矩阵的压缩存储
- Vijos 3736 监狱重排
- 微信小程序模板中使用循环
- 小demo
- 熔断
- python笔记 11-01-2017 kmeans +random
- js实现图片上传
- js url传值为中文的时候,页面接收乱码
- JavaScript
- 第7章 成员资格、授权(Authorize、ASP.NET Identity、OAuth和OpenID的外部登录)和安全性
- 设计模式--Pimpl(pointer to implementation 指向实现的指针)