use*_*808 5 javascript requirejs backbone.js
在最小的应用程序中使用RequireJS和Backbone,我总是得到
Uncaught Error: Mismatched anonymous define() module
Run Code Online (Sandbox Code Playgroud)
即使该应用程序继续工作.这是:https: //assets.site44.com/admin/
我在index.html中包含jQuery,下划线,主干,因为我想缩短每个视图/模型中的define()样板.
https://assets.site44.com/admin/js/main.js由
var l = console.log.bind(console)
var app
//l("AA")
require.config({
paths: {
// Major libraries
/*jquery: 'libs/jquery/jquery-min',
underscore: 'libs/underscore/underscore-min', // https://github.com/amdjs
backbone: 'libs/backbone/backbone-min', // https://github.com/amdjs
*/
// Require.js plugins
text: 'text'
}
})
function initApp() {
console.log("BB")
require([
'views/AppView'
], function(AppView){
l("CC")
app = new AppView()
$("#app").html(app.render())
})
}
$(document).ready(initApp)
Run Code Online (Sandbox Code Playgroud)
我无法从文档或这个回答的问题中找出问题: 匿名的define()模块不匹配
谢谢
我在index.html 中包含了jQuery、下划线、主干,因为我想缩短每个视图/模型中的define() 样板文件。
你不应该。如果你用谷歌搜索“未捕获的错误:不匹配的匿名定义()模块”,你会注意到最上面的链接是 RequireJS 的常见问题解答,解释了这一点
如果您在 HTML 中手动编写脚本标记以通过匿名 Define() 调用加载脚本,则可能会发生此错误。
- 编辑
如果您使用 grunt,则可以使用grunt-generate根据您自己的自定义模板轻松创建模块,而样板过载可能会毁掉您的一天:)
免责声明:我编写了 Grunt 插件。