ビューのバックボーンテンプレートは自動的にレンダリングされません。実際、バックボーンのドキュメントには、それを行う方法の例がいくつかあります。
ビューでテンプレートを使用する場合は、初期化時にレンダリングする必要があり、次のようにコードを記述できます。
var InvoiceForm = Backbone.View.extend({
template: _.template(addform),
render: function() {
this.$el.html(this.template());
return this;
},
initialize: function () {
this.render(); // Rendering your template in your this.el element
this.$("#buyer").val("test"); // Setting the value of #buyer in your template
}
});
後でこのビューを次のように使用できます。
var form = new InvoiceForm({ el: $("#wrapper_for_invoiceform") });
このフィドルのデモを確認してください:http://jsfiddle.net/hsn7J/