backbone.js 和backbone.modelbinding.js 以及 require.js
我试图遵循我在这里和其他几个地方看到的示例代码,使用 require.js 加载主干/下划线。我基本上复制/粘贴了 使用 RequireJS 加载 Backbone 和 Underscore 但它不起作用。
在 app.js 中显示警报(Backbone),Backbone 为 null。我不太确定为什么它不在那里 - 有人能看到我做错了什么吗?感谢您的帮助。
index.html
<script type="text/javascript" data-main="scripts/main" src="scripts/require.js"></script>
脚本/main.js
require.config({
paths: {
'jquery': 'libs/jquery-1.7.1',
'underscore': 'libs/underscore',
'backbone': 'libs/backbone'
}
});
require([
'libs/domReady',
'app/app'
], function(domReady, app){
domReady(function () {
app.initialize();
});
});
脚本/app/app.js
define([
'jquery',
'underscore',
'backbone'
], function($, _, Backbone){
return {
initialize: function(){
// examples say you can use $, _ or Backbone here
// but Backbon is null here... WTF???
alert(Backbone);
}
};
});
以下是我拥有的版本,以防重要的情况: jquery 1.7.1 require.js 版本 1.0.4 下划线1.3.0 主干版本0.5.3 模型绑定 0.4.3
I'm trying to follow the example code that i've seen here and several other places for loading backbone/underscore with require.js. i've basically copy/pasted the example code from Loading Backbone and Underscore using RequireJS but it isn't working.
in app.js the alert(Backbone) displays, Backbone is null. I'm not really sure why it isn't there - can anybody see what i'm doing wrong? thanks for any help.
index.html
<script type="text/javascript" data-main="scripts/main" src="scripts/require.js"></script>
scripts/main.js
require.config({
paths: {
'jquery': 'libs/jquery-1.7.1',
'underscore': 'libs/underscore',
'backbone': 'libs/backbone'
}
});
require([
'libs/domReady',
'app/app'
], function(domReady, app){
domReady(function () {
app.initialize();
});
});
scripts/app/app.js
define([
'jquery',
'underscore',
'backbone'
], function($, _, Backbone){
return {
initialize: function(){
// examples say you can use $, _ or Backbone here
// but Backbon is null here... WTF???
alert(Backbone);
}
};
});
Here's the versions I have in case that's important:
jquery 1.7.1
require.js version 1.0.4
underscore 1.3.0
backbone version 0.5.3
modelbinding 0.4.3
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我们可以看看您的文件结构和文件名吗?
你的骨干文件是@
libs/backbone.js
吗?或者是libs/backbone-0.5.3.js
还是什么?下划线和其他库也是如此,名称必须正确。
Can we see your file structure, with file names?
is your backbone file @
libs/backbone.js
? or is itlibs/backbone-0.5.3.js
or something?same goes for underscore and other libraries, the name has to be correct.