我有两个模板(标题和详细信息)
我的问题是当我运行应用程序时,它不会替换标题占位符内的详细信息模板。
查看1
var CalendarView = Backbone.View.extend({
el: '#header',
model: todo,
initialize: function () {
this.render();
this.monthView = new MonthView({ el: "#dvDetail", model: this.model });
},
render: function () {
template.render("testHeader.htm", $(this.el), { data: this.model.toJSON() });
}
});
查看2
var MonthView = Backbone.View.extend({
initialize: function () {
this.model.bind("change", this.render, this);
this.render();
},
render: function () {
template.render("testDetail.htm", $(this.el), { data: this.model.toJSON() });
}
});
的index.html
<div id="header"></div>
testHeader.htm
<div>This is header </div>
<div id="dvDetail">Sub template should be replace here...</div>
testDetail.htm
<div>This is details template and replaced on #dvDetail html</div>
当我运行应用程序时,它将显示
This is header
Sub template should be replace here...
我需要
This is header
This is details template and replaced on #dvDetail html
任何机构都可以让我知道此代码中缺少什么来获得所需的输出吗?任何线索都将受到高度赞赏!
答案 0 :(得分:0)
如果您使用下划线或lodash,这是我对渲染功能的建议......
....
template: _.template("testDetail.htm"), //just a sample , as an idea
el: '#header',
model: todo,
initialize: function () {
this.render();
this.monthView = new MonthView({ el: "#dvDetail", model: this.model });
},
render: function() {
this.$el.html(template); //this will do the trick for you
}
....
和您的MonthView相同......