所以我试图<table>
在 Backbone 中抽象我的工作,所以我创建了一个扩展我的“基本视图”的“表格视图”。因此,当我需要一个新表时,我可以扩展“表视图”并希望将“表视图”指向我希望它呈现的 DOM 元素,即。像这样:
app.Views.quotesList = app.Views.table.extend({
template: '#tmpl-table',
initialize: function(){
this.collection = new Backbone.Collection([
{name: "Tim", age: 5},
{name: "Ben", age: 26},
{name: "Rob", age: 55}
]);
},
render: function() {
var that = this;
var template = Handlebars.compile( $(this.template).html() );
$(this.el).html(template({id: 'quotes'}));
this.table = this.$('#table-quotes');
this.thead = this.table.find('thead tr');
this.tbody = this.table.find('tbody');
var template = Handlebars.compile( $('#table-heading').html() );
that.thead.append(template(that.collection.first().toJSON()));
var template = Handlebars.compile( $('#table-row').html() );
that.collection.each(function(model){
that.tbody.append(template(model.toJSON()));
});
return this;
},
});
我想将大部分通用代码移到表格视图中:
app.Views.table = app.Views.base.extend({
initialize: function(){
}
});
那么我将如何告诉“表视图”从“quotesList 视图”中渲染哪个元素?