【发布时间】:2013-10-22 08:37:38
【问题描述】:
如何使用 mustache 中的参数值使 if and else 符合逻辑?
喜欢:
if ($a == "yes")
action
else
action
或喜欢,
if ($a == "yes")
action
else if ($a == "maybe")
else
action
【问题讨论】:
如何使用 mustache 中的参数值使 if and else 符合逻辑?
喜欢:
if ($a == "yes")
action
else
action
或喜欢,
if ($a == "yes")
action
else if ($a == "maybe")
else
action
【问题讨论】:
Mustache 可用于 HTML、配置文件、源代码 - 任何东西。它通过使用散列或对象中提供的值扩展模板中的标签来工作。
我们称其为“无逻辑”,因为没有 if 语句、else 子句或 for 循环。相反,只有标签。一些标签被替换为一个值,一些什么都没有,而另一些则是一系列值。
如果假设一般情况下您的陈述如下:
enter code here if(notified_type == "Friendship")
data.type_friendship = true;
else if(notified_type == "Other" && action == "invite")
data.type_other_invite = true;
那么你可以写成
{{#type_friendship}}
friendship...
{{/type_friendship}}
{{#type_other_invite}}
invite...
{{/type_friendship}}
【讨论】: