2013-06-19 40 views
0

我有兩個模板(標題和詳細信息)子模板不使用的渲染骨幹,並強調

  • 包頭包含了一些細節,也對細節部分
  • 詳細含有一些細節佔位符。

我的問題是當我運行應用程序時,它不會替換標題佔位符內的Details模板。

視圖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

如果您正在使用下劃線或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 ...