我正在寻找一个使用 Mustachejs
和 Nodejs
这是我的示例,但它不起作用。 Mustache
未定义。
我正在使用 master 分支中的 Mustachejs。
var sys = require('sys');
var m = require("./mustache");
var view = {
title: "Joe",
calc: function() {
return 2 + 4;
}
};
var template = "{{title}} spends {{calc}}";
var html = Mustache().to_html(template, view);
sys.puts(html);
最佳答案
我通过 npm 安装 mustache,使用正确的 require 语法并(如 Derek 所说)将 mustache 用作对象而不是函数,从而使您的示例正常工作
npm install mustache
然后
var sys = require('sys');
var mustache = require('mustache');
var view = {
title: "Joe",
calc: function() {
return 2 + 4;
}
};
var template = "{{title}} spends {{calc}}";
var html = mustache.to_html(template, view);
sys.puts(html);
关于node.js - 使用 node.js 的服务器端 mustache.js 示例,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2493460/