モデルのビューをレンダリングするために、(coffeescriptではなく)javascriptでbackbone-on-railsgemを使用しています。すべて正常に動作しますが、私のビューコードは少し長いので、includes/partialsを使用するためにリファクタリングしたいと思います。
これが私のコードです:
私のviews/model_show.jsファイルで
AppName.Views.ModelNameShow = Backbone.View.extend({
template: JST['main'],
initialize: function() {
this.render();
},
render: function() {
this.model.fetch({async:false});
$(this.el).html(this.template({ model: this.model }))
$('#main_content').html(this.el);
}
});
テンプレートファイルで、templates/main.jst.ejsにこのようなものを入れたいと思います
<% if(this.model) { %>
<h2> model found</h2>
<%- include top_section %>
<%- include middle_section %>
<%- include bottom_section %>
<% } else { %>
<h3>Claim not found <a href='#'>Back</a></h3>
<% } %>
ここで、top_sectionはテンプレートの下のファイルです(templates / top_section.jst.ejsなど)
問題は、次のエラー(firebugの出力)が発生し続けることです。
SyntaxError:括弧内に)がありません[Break On This Error]
...2>モデルが見つかりました\n\ t'、(''+ include top_section).replace(/&/ g、'&')。replace(/
テンプレートがレンダリングされないため、このエラーが発生します
TypeError: this.template is not a function
[Break On This Error]
$(this.el).html(this.template({ model: this.model }))
以下のようないくつかの異なる構文を試しましたが、それらは異なるエラーをスローするだけです。
<%= include top_section %>
<%- include(top_section) %>
前もって感謝します