Templates 子模板未使用主干线和下划线进行渲染
我有两个模板(标题和详细信息)Templates 子模板未使用主干线和下划线进行渲染,templates,backbone.js,underscore.js,Templates,Backbone.js,Underscore.js,我有两个模板(标题和详细信息) 标题包含一些详细信息,也包含详细信息部分的占位符 详细信息包含更多的详细信息 我的问题是,当我运行应用程序时,它不会替换标题占位符中的详细信息模板。 视图1 var CalendarView = Backbone.View.extend({ el: '#header', model: todo, initialize: function () { this.render();
- 标题包含一些详细信息,也包含详细信息部分的占位符
- 详细信息包含更多的详细信息
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>
我需要
This is header
This is details template and replaced on #dvDetail html
任何人都可以让我知道这段代码中缺少了什么以获得所需的输出吗?任何线索都将不胜感激 如果您使用下划线或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也一样
This is header
Sub template should be replace here...
This is header
This is details template and replaced on #dvDetail html
....
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
}
....