如何定义与Backbone结合使用的Jade模板 [英] How to define jade template for using with Backbone
本文介绍了如何定义与Backbone结合使用的Jade模板的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要使用模板来渲染每个ItemView:
I need to use template for rendering of each ItemView:
var ItemView = Backbone.View.extend({
className: 'item',
template: _.template($('#itemTemplate').html()),
initialize: function () {
}
});
所以我首先需要定义html模板:
So I need to define html template at first:
<script id="itemTemplate" type="text/template">
<img src="<%= photo %>" alt="<%= name %>" />
<h1><%= name %><span><%= type %></span></h1>
<div><%= address %></div>
<dl>
<dt>Tel:</dt><dd><%= tel %></dd>
<dt>Email:</dt><dd><a href="mailto:<%= email %>"><%= email %></a></dd>
</dl>
但是我使用Nodejs Jade模板引擎,但是我不明白我在其中定义了shuold的方式. 请帮助.
But I use Nodejs Jade Template Engine and I don't understand how shuold I define in it. Help please.
推荐答案
这很简单,但是有一个陷阱:您不希望Jade逃避属性内容,所以使用foo!='<%= bar &%>'
而不是foo='<%= bar &%>'
.
That's easy, but there's one catch: You don't want Jade to escape attributes content so use foo!='<%= bar &%>'
instead of just foo='<%= bar &%>'
.
我们在这里:
script#itemTemplate(type='text/template')
img(src!='<%= photo %>', alt!='<%= name %>')
h1 <%= name %>
span <%= type %>
div <%= address %>
dl
dt Tel:
dd <%= tel %>
dt Email:
dd
a(href!='mailto:<%= email %>') <%= email %>
它已经过测试,因此您可以立即使用它:)
It's tested, so you can use it right away :)
这篇关于如何定义与Backbone结合使用的Jade模板的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文