欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

微信小程序 教程之模板

 更新時(shí)間:2016年10月18日 10:38:19   投稿:lqh  
這篇文章主要介紹了微信小程序 模板的相關(guān)資料,并附實(shí)例代碼,需要的朋友可以參考下

系列文章:

微信小程序 教程之WXSS
微信小程序 教程之引用
微信小程序 教程之事件
微信小程序 教程之模板
微信小程序 教程之列表渲染
微信小程序 教程之條件渲染
微信小程序 教程之?dāng)?shù)據(jù)綁定
微信小程序 教程之WXML

模板

WXML提供模板(template),可以在模板中定義代碼片段,然后在不同的地方調(diào)用。

定義模板

使用name屬性,作為模板的名字。然后在<template/>內(nèi)定義代碼片段,如:

<!--
 index: int
 msg: string
 time: string
-->
<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'
 }
 }
})

is屬性可以使用Mustache語(yǔ)法,在運(yùn)行時(shí)來(lái)決定具體需要渲染哪個(gè)模板:

<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傳入的數(shù)據(jù)。

感謝閱讀,希望能幫助到大家,謝謝大家對(duì)本站的支持!

相關(guān)文章

最新評(píng)論