Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/templates/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Templates 子模板未使用主干线和下划线进行渲染_Templates_Backbone.js_Underscore.js - Fatal编程技术网

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();

我有两个模板(标题和详细信息)

  • 标题包含一些详细信息,也包含详细信息部分的占位符
  • 详细信息包含更多的详细信息
我的问题是,当我运行应用程序时,它不会替换标题占位符中的详细信息模板。

视图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>
我需要

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
   }

....