使用requirejs加载小胡子 [英] Loading mustache using requirejs
本文介绍了使用requirejs加载小胡子的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想通过requirejs加载和使用小胡子。
I would like to load and use mustache by requirejs.
也许这个问题已经问过:
使用RequireJS使用Mustache的模块加载错误
Maybe this question has already asked:
AMD Module Loading Error with Mustache using RequireJS
无论如何,我想弄清楚如何修复我的代码:
Anyway I am trying to figure out how can I fix my code:
main.js
require.config({
paths: {
jquery: 'libs/jquery/jquery',
underscore: 'libs/underscore/underscore-min',
backbone: 'libs/backbone/backbone-optamd3-min',
mustache: "libs/mustache/mustache"
}
});
require([
'views/app'
], function(AppView){
var app_view = new AppView;
});
app.js
define([
'jquery',
'underscore',
'backbone',
"mustache"
], function($, _, Backbone, Mustache) {
console.log($, _, Backbone, Mustache); // <-- *** Mustache is null ***
// ......
}
);
正如您在<$的评论中所看到的c $ c> app.js 文件, Mustache为空
...
我应该使用另一个Mustache库吗?
这里我使用的是 Moustache
推荐答案
您应该在胡子目录中创建一个新文件mustache-wrap.js,如下所示:
You should just create in your mustache directory a new file mustache-wrap.js which looks like this:
define(['libs/mustache/mustache'], function(Mustache){
// Tell Require.js that this module returns a reference to Mustache
return Mustache;
});
然后你的主要是:
mustache: "libs/mustache/mustache-wrap"
这篇关于使用requirejs加载小胡子的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文