2013-03-15 45 views
0

我試圖將這個jQuery模板轉換爲一個underscorejs模板,但沒有意義爲什麼它不工作。誰能解釋爲什麼?從舊的轉換下劃線模板的錯誤

 el: $('#contents'), 
    template: _.template(MenuTemplate), 
    //template: $('#item-tmpl').template(), 

    render: function() 
    { 
    this.$el.empty(); 

    //$.tmpl(this.template, this.model.toArray()).appendTo(this.el); 
    // Old jquery template 


    //this.$el.html(this.template(this.model.toArray()).appendTo(this.el)); 
    //underscore template 

     return this; 
    } 
+0

什麼不工作?我不明白你使用模板並設置到根元素的技巧(不需要調用appendTo)。請參閱[這裏](http://backbonejs.org/#View-render)。 – WiredPrairie 2013-03-15 10:49:25

回答

1

你有點過您使用的模板。試試這個:

el: $('#contents'), 
template: _.template(MenuTemplate), 

render: function() 
{ 
    this.$el.empty(); 

    this.$el.html(this.template(this.model.toArray())); 

    return this; 
} 
+0

以前試過這個,但是在chrome中有一個錯誤'Uncaught ReferenceError:position is not defined' – koko 2013-03-18 03:29:45

+0

這裏是我從backbonejs網站獲得的示例https://www.dropbox.com/s/ixk4htvgenx87y0/bbgek.zip – koko 2013-03-18 03:44:03