我一直从 Backbone 开始。我使用 Require 加载模块并收到此错误。谁能解释一下?在文件 user.js 中,当我尝试创建 Backbone.Model.extend 时,我遇到了这个错误。我使用了 Backbone.js 0.9.10、jQuery v1.9.0、RequireJS 2.1.4、Underscore 1.4.4。谢谢你。
索引.html
<!doctype html>
<html lang="en">
<head>
<title></title>
<!-- Load the script "js/main.js" as our entry point -->
<script data-main="js/main.js" src="js/libs/require/require.js"></script>
<link rel="stylesheet" type="text/css" href="stylesheets/style.css">
</head>
<body>
<div id="container">
<div id="menu"></div>
<div id="content"></div>
</div>
</body>
</html>
main.js
require.config({
paths:{
jquery:'libs/jquery/jquery-min',
underscore:'libs/underscore/underscore-min',
backbone:'libs/backbone/backbone-min',
templates:'../templates'
}
});
require(['app'], function (App) {
console.log('____main.js')
App.initialize();
console.log('main.js')
});
应用程序.js
define(['jquery', 'underscore', 'backbone', 'router'], function($, _, Backbone, Router) {
var initialize = function(){
Router.initialize();
console.log('app.js');
};
return {
initialize: initialize
};
});
路由器.js
define([
'jquery',
'underscore',
'backbone',
'views/home/login'
//'views/room',
// 'views/friend',
// 'views/play',
// 'views/money'
], function ($, _, Backbone, loginView) {
console.log('router.js');
var AppRouter = Backbone.Router.extend({
routes:{
'/home':'showHome',
'*actions':'defaultAction'
},
showHome:function () {
loginView.render();
},
defaultAction:function (actions) {
console.log('No route:', actions);
}
});
var initialize = function(){
var app_router = new AppRouter;
Backbone.history.start();
};
return {
initialize: initialize
};
});
login.js(主干视图)
define([
'jquery',
'underscore',
'backbone',
'collections/home/users',
'text!templates/home/login.html'
], function($, _, Backbone, usersCollections, homeLoginTemplate){
var loginView = Backbone.View.extend({
el: $('container'),
render: function(){
var data = {};
var compiledTemplate = _.template(homeLoginTemplate);
this.el.append(compiledTemplate);
}
});
console.log('login.js');
return new loginView;
});
user.js(骨干模型)
define([
'underscore',
'backbone'
], function (_, Backbone) {
console.log('user model');
var userModel = Backbone.Model.extend({
default:{
username:"",
password:""
}
});
return userModel;
});
users.js(主干集合)
define(['underscore', 'backbone', 'models/user'], function (_, Backbone, userModel) {
console.log('user collection');
var usersCollection = Backbone.Collection.extend({
model:userModel
});
return new usersCollection;
});
我不能发我的照片。但是您可以在此链接中看到http://imageshack.us/photo/my-images/809/devi.jpg/。