2012-08-11 92 views
1

嗨。我正試圖在rails項目中從骨幹視圖調用灰塵模板。如何從骨幹視圖調用灰塵模板

這是調用JST模板的方式:

Spa.Views.PostsIndex = Backbone.View.extend({ 

模板:JST [ '帖/指數'],

我需要用土代替ERB。我正在使用dust_assets gem來渲染灰塵模板。

我在app/assets/templates/post下有一個文件index.jst.dust模板。

當我從下面的application.js文件調用模板時,我能夠渲染灰塵模板,但我無法從骨幹視圖渲染它。

$(function() { 


JST["templates/index"]({ name : "World" }, function(err, out) { 
$('#dust').html(out); 
    }); 
}); 

請建議我如何調用防塵模板或指向我解釋相同的一些鏈接。

+0

我把這種方法,並且它的偉大工作: http://stackoverflow.com/questions/12758506/how-to-render-dust-template -with骨幹 – granmoe 2014-11-16 01:34:25

回答

0

backbone.js的View類有一個無操作的渲染方法 - 這意味着你必須重寫此方法來告訴View類如何渲染它的視圖。

即使您在類中定義了模板變量,您也必須這樣做。

一個例子是:

render: function() { 
    this.template({name: "World"}, function(err, out){ 
    $(this.el).html(out); 
    }); 
    return this; 
}