微信小程序模板template的使用
来源:互联网 发布:差评黑市淘宝店叫什么 编辑:程序博客网 时间:2024/05/20 04:47
- 一层 template 的使用
- 两层 template wxfor的使用
WXML提供模板(template),可以在模板中定义代码片段,然后在不同的地方调用。官方API
一层 template 的使用
使用name属性,作为模板的名字。然后在 template 内定义代码片段,如:
<template name="msgItem"> <view> <text> {{index}}: {{msg}} </text> <text> Time: {{time}} </text> </view></template>
使用 is 属性,声明需要的使用的模板,然后将模板所需要的 data 传入,这是利用数组一次传三个值,在用数组传值的时候,数组前面加三个 ‘.’,如:
<template is="msgItem" data="{{...item}}"/>
Page({ data: { item: { index: 0, msg: 'this is a template', time: '2016-09-15' } }})
也可以用单独的参数传值,单独的参数传值的时候,参数中间用逗号隔开,如
<template is="msgItem" data="{{ index,msg,time }}"/>
data:{ index: 0, msg: 'this is a template', time: '2016-09-15' }
如果template单独放在一个文件夹里面,在其他 .wxml 页面调用它的时候先导入放 template 标签的 .wxml 如
<import src="../common/common.wxml"></import>
两层 template +wx:for的使用
定义模板文件 common.wxml
<template name="board-tem" > <view wx:for="{{ arra }}" > <block wx:for="{{ item }}" wx:for-item="items" wx:key="items.key"> <template is="inner-tem" data="{{ items }}"></template> </block> </view></template><template name="inner-tem"> <navigator url="../item/item?key={{ items.key }}"> <view > <text >{{ items[0] }}</text> <text >{{ items[1] }}</text> <text >{{ items[2] }}</text> </view> </navigator></template>
使用模板文件 index.wxml
<import src="../common/common.wxml"></import><template is="board-tem" data="{{ arra }}"></template>
index.js内容
data:{ arra:[['a','b','c'],['1','2','3'],['A','B','C']] },
阅读全文
0 0
- 微信小程序 template模板的使用
- 微信小程序模板template的使用
- 微信小程序-template模板使用
- 微信小程序中template模板使用
- 微信小程序11---模板template
- 类模板template的使用!
- c++模板 template的使用
- 微信小程序给嵌套template模板传递数据的方式
- 微信小程序视图template模板引用
- 微信小程序如何使用template
- C++中 模板Template的使用
- C++中 模板Template的使用
- C++中 模板Template的使用
- C++中 模板Template的使用
- C++中 模板Template的使用
- C++中 模板Template的使用
- C++中 模板Template的使用
- C++中 模板Template的使用
- Cache
- MFC——LIstCtrl中嵌入Edit和Combobox控件
- Kotlin_类
- android studio中MainActivity的R找不到
- Meterpreter基础命令
- 微信小程序模板template的使用
- Storm Kafka + Storm + HBase实例
- c++成员变量的初始化顺序
- 算法题目-删除链表中重复的结点
- 《UNIX网络编程 卷1》 笔记: 基本UDP套接字编程
- 半平面交 模板 bzoj2618 【Cqoi2006】凸多边形
- LeetCode之路:404. Sum of Left Leaves
- Java 8 – 将 Stream 转换为 List
- HTML5之画布(canvas)(一)