我正在尝试更多地了解requireJS。所以,如果我理解正确,下面的代码应该是合法的。这是使我的应用程序模块化的正确方法吗?
这是application.js
,其中data-main
属性指向:
requirejs.config({
baseUrl: 'scripts/vendor', // By default, load all from vendor folder
shim: {
'backbone' : { // Do not support module loading
deps: ['underscore', 'jquery'], // Do not support module loading
exports: 'Backbone'
},
},
paths: {
models: '../application/models', // Load from this folder if starts with user
views: '../application/views', // As above...
}
});
requirejs(['jquery', 'backbone', 'views/user'], function($, Backbone, UserView) {
});
我的视图/模型模块(现在非常没用):
文件application/views/user.js
:
// underscore should be loaded now
define(['jquery', 'backbone', 'models/user'], function($, Backbone, User) {
return Backbone.View.extend({
model: User,
el: $('tr'),
initialize: function() {}
});
});
文件application/models/user.js
:
define(['backbone'], function(Backbone) { // underscore should be loaded now
return Backbone.Model.extend({
});
});