バックボーンを学ぼうとしていますが、ハンドルバーに問題があります。
ビューとテンプレート用に別々のファイルがあるモジュラーアプリを作成したいと思います。
これが私のapp.jsです:
define([
// Application.
"app",
"views/home",
],
function(app, homeView){
var Router = Backbone.Router.extend({
routes: {
"": "index",
"home": "home"
},
index: function() {
console.log('hello');
},
home: function() {
console.log('home');
homeView.render();
}
});
return Router;
});
この時点で、コンソールに「ホーム」が表示されます。
これがviews/home.jsです
define([
'app',
'text!templates/home.html'
], function(app, homeTxt) {
var homeView = Backbone.View.extend({
el: $('#main'),
render: function(){
console.log('render');
var data = { property : "1" };
this.template = Handlebars.compile(homeTxt);
this.el.append( this.template() );
}
});
return new homeView;
});
これで、コンソールで「render」を取得する必要がありますが、取得できず、「templates/home.html」のテンプレートがレンダリングされません。
コンソールでもDOMでもエラーは発生しません。