1

根据这个问题,检查false传递给 mustache 模板的 json 对象是这样完成的:

{{^like}}
    it is false
{{/like}}
{{#like}}
    it is true
{{/like}}

假设 json 看起来像这样{"like":true}

但是在Mustache 演示页面上尝试这个并没有按预期进行。html 输出如下所示:

it is true
it is false
{{/like}}

{{^whatever}}当您的模板中有内容时,为什么它会中断?这不是检查的正确方法false吗?

4

1 回答 1

1

倒排部分 (^) 在Mustache github上实现,但MustacheDemoIO使用不支持该库的过时版本。在过时的代码中,您可以找到:

// for each {{#foo}}{{/foo}} section do...
  return template.replace(regex, function(match, name, content) {
    var value = that.find(name, context);
    if(that.is_array(value)) { // Enumerable, Let's loop!
      return that.map(value, function(row) {
        return that.render(content, that.merge(context,
                that.create_context(row)), partials, true);
      }).join("");
    } else if(value) { // boolean section
      return that.render(content, context, partials, true);
    } else {
      return "";
    }
  });

但是 {{^foo}} {{/foo}} 什么都没有。这就是为什么它停止你的例子。

但这应该不是什么大问题,因为Mustache github上提供的最新版本具有此功能。

于 2013-09-17T14:30:26.070 回答