微信小程序> 微信小程序模板中使用循环

微信小程序模板中使用循环

浏览量:460 时间: 来源:weixin_33694172

原创文章

本篇介绍如何在模板里使用循环。
方法一:
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。

版权声明

即速应用倡导尊重与保护知识产权。如发现本站文章存在版权问题,烦请提供版权疑问、身份证明、版权证明、联系方式等发邮件至197452366@qq.com ,我们将及时处理。本站文章仅作分享交流用途,作者观点不等同于即速应用观点。用户与作者的任何交易与本站无关,请知悉。

产品经理

手机 : 13312967497

擅长 : 小程序流量变现

扫码领取礼包

热门模板

  • 头条
  • 搜狐
  • 微博
  • 百家
  • 一点资讯
  • 知乎