【发布时间】:2014-08-21 06:54:02
【问题描述】:
我正在尝试将 Mustache 与 requireJS 和 jQuery 一起使用,由于 Chrome 的控制台输出正确,因此它似乎正在加载到浏览器中:
>$.mustache
<function (template, view, partials) {
return Mustache.render(template, view, partials);
}
但是当我尝试使用 mustache 函数时,它会给出错误 ReferenceError: Mustache is not defined 并指向 mustache.js 文件本身的第 588 行:
$.mustache = function (template, view, partials) {
return Mustache.render(template, view, partials);
};
这是我在 main.js 文件中调用它的方式:
require(['mustache'], function(Mustache){
var view = {test:'TEST'};
var temp = '{{test}}!!!';
$.mustache(temp,view);
});
【问题讨论】:
-
好吧,如果你在控制台中测试,只要调用 js,它肯定会工作。如果它在代码中不起作用,可能是因为您在调用 js 之前尝试使用它
-
查看此链接希望对您有所帮助stackoverflow.com/questions/6439935/…
-
问题是它似乎甚至无法在控制台中运行。
$.mustache本身被定义为一个函数,但是当我尝试使用它时,它说Mustache没有定义。而且在源代码中似乎也没有任何定义。也许我缺少额外的源代码?据我所知,我从官方网站获得的只是 jquery.mustache.js。
标签: javascript jquery requirejs mustache