我尝试了这些教程first和second以及third,但骨干网仍无效。控制台输出显示:“Uncaught TypeError:无法调用未定义的方法'扩展'
文件夹结构是:
index.html
resources
js
b.js
main.js
meinmodul.js
libs
backbone.js
jquery-1.7.1.js
requireJS_2.1.5.js
underscore.js
的index.html:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html><head>
<title>test</title>
<!--Require JS -->
<script data-main='resources/js/main' src='resources/libs/requireJS_2.1.5.js'></script</head>
<body>
<div id='wrapper'>
<span>Hallo!</span>
<div id='foo'>foo</div>
</div></body></html>
main.js:
requirejs.config({
paths: {
framework: '../libs',
jquery:'../libs/jquery-1.7.1',
underscore:'../libs/underscore',
backbone:'../libs/backbone'
},
shim: {
'underscore': {
'exports': '_'
},
'backbone': {
'deps': ['jquery', 'underscore'],
'exports': 'Backbone'
},
}
});
require(['jquery', 'meinmodul'], function(jq, meinmodul) {
alert('div foo is foo');
$('#foo').html('bar');
});
require(['jquery','backbone','b'], function(jq, Backbone, test) {
console.log("my backbone view");
});
b.js:
define(['jquery','backbone'], function($,Backbone) {
var SearchView = Backbone.View.extend({
events: {
"click": 'savenow'
},
initialize: function(){
console.log("init1");
console.log($('#testid'));
},
savenow: function(){
console.log("test save method");
}
});
//return SearchView;
return {
'SearchView': SearchView
};
});
我错过了什么或我做错了什么?
答案 0 :(得分:0)
您似乎错过了require.config()中的baseUrl。
如果未手动设置baseUrl,则所有js路径都基于html路径。