【问题标题】:"If logic" based on function output in mustache.js基于 mustache.js 中函数输出的“如果逻辑”
【发布时间】:2016-11-17 16:30:00
【问题描述】:

基于How do I accomplish an if/else in mustache.js?calling function with arguments in mustache javascript,我知道我可以在 mustache.js 模板中创建条件,还可以调用函数在渲染的 HTML 上打印一些内容。

但是它们可以结合起来吗?也就是说,我们可以“如果”一个函数的结果吗?

在伪代码中:

If someFunction(args){ 
    // print something
}

使用 mustache.js 表示法:

{{#someFunction}}someValue{{/someFunction}}

这将输出 someFunction 的评估结果。我们可以仅在函数的评估为正时打印吗?

我知道“无逻辑模板”,但开发人员必须做开发人员必须做的事情。

【问题讨论】:

    标签: javascript mustache


    【解决方案1】:

    您需要您的函数返回一个值,然后在您的 if 语句中评估该值。这是一般逻辑如下...

    function returnBool(b){
       return b;
    }
    
    if (returnBool(true) === true){
      mustache.render();
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-09-15
      • 2018-08-06
      • 1970-01-01
      • 2023-03-15
      • 1970-01-01
      • 2012-04-27
      • 1970-01-01
      相关资源
      最近更新 更多