javascript Mustache.render() 和 Mustache.to_html() 有什么区别?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10872615/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-26 11:19:24  来源:igfitidea点击:

What is the difference between Mustache.render() and Mustache.to_html()?

javascriptmustache

提问by ehabd

The documentationmakes no mention of Mustache.to_html(), but every tutorialfor Mustache.js online uses Mustache.to_html(). Therefore I am surely missing some jewels.

文件没有提及Mustache.to_html()的,但每一个教程为Mustache.js在线使用Mustache.to_html()。因此,我肯定缺少一些珠宝。

Code examples would be very much appreciated.

代码示例将不胜感激。

回答by McGarnagle

Looking at the source, it seems to_htmlhas essentially been deprecated:

查看源代码,似乎to_html基本上已被弃用:

// This is here for backwards compatibility with 0.4.x.
exports.to_html = function (template, view, partials, send) {
    var result = render(template, view, partials);

    if (typeof send === "function") {
      send(result);
    } else {
      return result;
    }
};

As you can see it invokes render. The one difference is the extra (optional) sendparameter, which is a callback it invokes (sending the result as a parameter).

如您所见,它调用了render。一个区别是额外的(可选)发送参数,这是它调用的回调(将结果作为参数发送)。