Underscore/Backbone 模板.get

Underscore/Backbone Templates .get

是否可以在 underscore/backbone 模板中使用 .get('property')

示例:

正在向模板传递数据:

var pageTemplate = _.template( PageTemplate, this);
$(this.el).html(pageTemplate);

自己的模板:

 <div id="productContainer" style="left:<%= 1 + (450 - model.get('previewHeight'))/2 %>px;"></div>

谢谢。

是的,应该可以。

var my_json = {};
my_json.model = my_model;

var html_template = _.template($("#my_template").html());
$(this.el).html(html_template(my_json));

<div id="my_template" style="left:<%= 1 + (450 - model.get('previewHeight'))/2 %>px;"></div>