マリオネット初挑戦です。マリオネット アプリケーションを requirejs モジュールとしてインスタンス化しようとしています。私は、Marionette.js wiki の Using Marionette with Require js 記事に従っています。
https://github.com/marionettejs/backbone.marionette/wiki/Using-marionette-with-requirejs
エラーなしで同じ場所にビュー、モデルなどをインスタンス化できるので、すべてのシム、依存関係、およびファイルが順番にあると思いますが、アプリケーションの問題を理解できません。ヘルプやガイダンスをいただければ幸いです。
これが私のindex.htmlです:-
<!DOCTYPE html>
<html>
<head>
<title>Marionette Structure and Require AMD Proto</title>
<link rel="stylesheet" type="text/css" href="css/styles.css">
</head>
<body>
<div id="nav">
</div>
<div id="mainContent">
</div>
<script language="javascript">
// convenience function, because console.log throws errors and crashes IE
// this way you don't need to all logs to test in IE
function trace(msg){
try{
console.log(msg);
}catch(e){
// suppressed error
}
}
</script>
<script src="js/lib/require.js" data-main="app.js"></script>
</body>
</html>
これが私のapp.jsです:-
require.config({
paths : {
backbone : 'js/lib/backbone',
underscore : 'js/lib/underscore',
jquery : 'js/lib/jquery',
marionette : 'js/lib/backbone.marionette'
},
shim : {
jquery : {
exports : 'jQuery'
},
underscore : {
exports : '_'
},
backbone : {
deps : ['jquery', 'underscore'],
exports : 'Backbone'
},
marionette : {
deps : ['jquery', 'underscore', 'backbone'],
exports : 'Marionette'
}
}
})
require(
["jquery",
"underscore",
"backbone",
"marionette",
"js/shell/shellapp"
],
function($, _, Backbone, Marionette, ShellApp) {
$(function() {
new ShellApp();
trace("ShellApp: "+ShellApp);
});
}
);
最後に、ここに私の shellapp.js があります:-
define( ["marionette"], function (Marionette) {
// set up the app instance
var ShellApp = new Marionette.Application();
// configuration, setting up regions, etc ...
ShellApp.addRegions({
nav: '#nav',
main: '#mainContent'
});
ShellApp.on('initialize:after', function(){
trace("initialize:after");
});
// export the app from this module
return ShellApp;
});
すべてをまとめると、app.js の 42 行目に「Uncaught TypeError: object is not a function」が表示されます
ここまで来てくれた人、本当にありがとう!
サム