-
Notifications
You must be signed in to change notification settings - Fork 13
模板 : if 结构
eprom2006 edited this page Feb 9, 2020
·
3 revisions
if 结构模板用于根据条件真假渲染不同的模板,它是一个object,可以有三个成员:
{
if:判断条件,
then:条件为真时渲染的模板(必选),
else:条件为假时渲染的模板(可选)
}
条件可以是布尔值或者布尔表达式。
{
if:(a===1),
then:{e:"div",t:"true template"},
else:{e:"div",t:"false template"}
}
条件也可以由函数来提供,当条件是一个函数时,thin.js会将当前容器和绑定的数据作为成员传递给函数,而函数应返回一个布尔值。
{
if:(p)=>{
return p.data.role==='销售'
},
then:{e:"div",t:"true template"},
else:{e:"div",t:"false template"}
}