小程序文档整理之 -- 模板
2017-08-25 10:55
134 查看
模板
WXML提供模板(template),可以在模板中定义代码片段,然后在不同的地方调用。定义模板
使用name属性,作为模板的名字。然后在<template/>内定义代码片段,如:
<!-- index: int msg: string time: string --> <template name="msgItem"> <view> <text> {{index}}: {{msg}} </text> <text> Time: {{time}} </text> </view> </template>
使用模板
使用 is 属性,声明需要使用的模板de名字,然后将模板所需要的 data 传入,如:<template is="msgItem" data="{{...item}}"/> Page({ data: { item: { index: 0, msg: 'this is a template', time: '2016-09-15' } } })
is 属性可以使用 Mustache 语法,来动态决定具体需要渲染哪个模板:
<template name="odd"> <view> odd </view> </template> <template name="even"> <view> even </view> </template> <block wx:for="{{[1, 2, 3, 4, 5]}}"> <template is="{{item % 2 == 0 ? 'even' : 'odd'}}"/> </block>
模板的作用域
模板拥有自己的作用域,只能使用data传入的数据。
相关文章推荐
- C#程序通过模板自动创建Word文档.doc
- 小程序文档整理之 -- 引用(import和include)
- 小程序文档整理之 -- API(媒体)
- 魔改——MFC MDI程序 定制 文档模板 运行时全部打开 禁用关闭按钮
- C#程序通过模板自动创建Word文档
- 小程序文档整理之 -- 条件渲染
- 小程序文档整理之 -- 快速上手
- 小程序文档整理之 -- API(文件)
- 【整理】MFC单文档程序窗口大小的设置
- 小程序文档整理之 -- API(数据缓存)
- 程序设计文档模板
- 小程序文档整理之 -- API(位置)
- C#程序通过模板自动创建Word文档
- 小程序文档整理之 -- API(设备)
- SQL Server 文档整理 - 5 胸闷测试小程序^_^
- 小程序文档整理之 -- 组件
- 小程序文档整理之 -- API(界面)
- C#程序通过模板自动创建Word文档
- 微信小程序官方文档错误整理
- 韩顺平_轻松搞定网页设计(html+css+javascript)_第19讲_js运行原理_js开发工具介绍_js程序(hello)_js基本语法_学习笔记_源代码图解_PPT文档整理