AMD模块加载错误使用RequireJS胡子 [英] AMD Module Loading Error with Mustache using RequireJS
问题描述
我在这里跟随tuturoial: http://backbonetutorials.com/organizing-backbone-采用模块/ 以及所有我想要做的是在骨干视图中使用胡子,而不是underscore.js我的模板引擎。一切工作,直到我尝试做更换胡子的预期。萤火虫给了我这样的:
为模块加载超时:胡子
我的胡子包装(在库/胡须/小胡子wrap.js
)是像这样:
定义(['库/小胡子/胡子'],函数(){
//告诉Require.js该模块返回胡子参考
返回胡子;
});
下面是code为我的骨干查看:
//协议详细内容查看
定义([
jQuery的,
下划线,
'骨干',
'胡子',
收藏/协议,
的文字!模板/协议/ protocoldetail.html
]函数($,_,骨干,小胡子,protocolCollection,protocolDetailTemplate){ VAR protocolDetailView = Backbone.View.extend({ EL:#资产的细节,
渲染:功能(PID){
this.collection =新protocolCollection;
this.collection.fetch();
VAR P = this.collection.getByCid('C'+ PID);
VAR模板={{名}};
htmlr = Mustache.to_html(模板,对);
$(this.el)的.html(htmlr);
// VAR compiledTemplate = _.template(protocolDetailTemplate,{协议:协议});
//$(this.el).html(compiledTemplate); }, 事件:{
#提交资产所有者:CHOWN
}, CHOWN:功能(PID){
的console.log(协议详细内容查看CHOWN回调。)
}
}); 返回新protocolDetailView;
});
我的 main.js
文件具有以下配置:
require.config({
路径:{
jQuery的:库/ jQuery的/ jQuery的,
jQueryUI的://ajax.aspnetcdn.com/ajax/jquery.ui/1.8.17/jquery-ui.min',
jstree:库/ jstree / jquery.jstree',
胡子:库/胡须/小胡子包装,
强调:库/下划线/下划线,
主要成分:库/骨干网/骨干
}
});
在你main.js文件,你拥有所有你需要,请务必小胡子添加到配置,而不用担心包装和只是尝试直接载入胡子。
require.config({
路径:{
强调:库/下划线
脊梁:库/脊梁,
胡子:库/小胡子/胡子
}
});
这可能会帮助...
另外,这里有一些起动器的应用程序来帮助你在你的要求,骨干旅程。
https://github.com/jcreamer898/RequireJS-Backbone-Starter < BR>
https://github.com/david0178418/BackboneJS-AMD-Boilerplate 结果
https://github.com/addyosmani/backbone-fundamentals 结果
https://github.com/amdjs
I am following the tuturoial here: http://backbonetutorials.com/organizing-backbone-using-modules/ and all I would like to do is use Mustache instead of underscore.js for my templating engine in a Backbone View. Everything is working as expected until I try to do the replacement of Mustache. Firebug gives me this:
Load timeout for modules: Mustache
My Mustache wrapper (in libs/mustache/mustache-wrap.js
) is like so:
define(['libs/mustache/mustache'], function(){
// Tell Require.js that this module returns a reference to Mustache
return Mustache;
});
Here is the code for my Backbone View:
// Protocol Detail View
define([
'jQuery',
'Underscore',
'Backbone',
'Mustache',
'collections/protocols',
'text!templates/protocol/protocoldetail.html'
], function($, _, Backbone, Mustache, protocolCollection, protocolDetailTemplate){
var protocolDetailView = Backbone.View.extend({
el: "#asset-detail",
render: function( pid ){
this.collection = new protocolCollection;
this.collection.fetch();
var p = this.collection.getByCid('c'+pid);
var template = "{{name}}";
htmlr = Mustache.to_html(template, p);
$(this.el).html(htmlr);
//var compiledTemplate = _.template( protocolDetailTemplate, { protocol: protocol });
//$(this.el).html(compiledTemplate);
},
events: {
"submit #asset-owner": "chown"
},
chown: function ( pid ){
console.log("Protocol Detail View chown callback.")
}
});
return new protocolDetailView;
});
My main.js
file has the following config:
require.config({
paths: {
jQuery: 'libs/jquery/jquery',
jQueryUI: '//ajax.aspnetcdn.com/ajax/jquery.ui/1.8.17/jquery-ui.min',
jstree: 'libs/jstree/jquery.jstree',
Mustache: 'libs/mustache/mustache-wrap',
Underscore: 'libs/underscore/underscore',
Backbone: 'libs/backbone/backbone'
}
});
In you main.js file where you have all you're requires, make sure to add Mustache to the config, and don't worry about the wrapper and just try loading Mustache directly.
require.config({
'paths': {
"underscore": "libs/underscore",
"backbone": "libs/backbone",
"Mustache": "libs/mustache/mustache"
}
});
That might help...
Also, here are some starter apps to help you out on your require, backbone journey.
https://github.com/jcreamer898/RequireJS-Backbone-Starter
https://github.com/david0178418/BackboneJS-AMD-Boilerplate
https://github.com/addyosmani/backbone-fundamentals
https://github.com/amdjs
这篇关于AMD模块加载错误使用RequireJS胡子的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!