【问题标题】:How make logical if and else with a parameter value in mustache如何使用 mustache 中的参数值使 if 和 else 合乎逻辑
【发布时间】: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

【问题讨论】:

    标签: templates mustache.php


    【解决方案1】:

    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}}
    

    【讨论】:

    • 在此处输入代码 if(notified_type == "Friendship") data.type_friendship = true;否则 if(notified_type == "其他" && action == "邀请") data.type_other_invite = true;
    猜你喜欢
    • 1970-01-01
    • 2011-03-13
    • 2016-03-24
    • 1970-01-01
    • 2022-08-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-02-10
    相关资源
    最近更新 更多