2012-10-24 54 views
3

您好我正在使用Backbone將Jade模板渲染爲HTML。視圖看起來是這樣的:在報價中渲染骨幹模板變量

script(type="text/template",id="waiting_call_template") 
    div(class="call-code") <%= channelId %> 
    div(style="display: inline-block; vertical-align: top; margin-right: 20px; width: 130px;") 
     div(class="statistic", title='<%= fullPage %>') <%= page %> 

當呈現,HTML輸出是這樣的:

<div title="&lt;%= fullPage%&gt;" class="statistic">test.html</div> 

發生這種情況,因爲整頁變量是加引號。如何使Backbone識別出即使它是在引號中,fullPage是一個變量?當您想要打印的報價之間的事情

div(class="statistic", title=<%= fullPage %>) 

回答

0

試試這個

div(class="statistic", title="#{fullPage}") #{page} 
+0

,讓這使得節點認爲該變量是未來服務器端玉渲染錯誤 – dshipper

0

,使用 「#{}」 語法:

+1

,當它實際上應該要填寫通過Backbone – dshipper

0

你嘗試從下劃線escape()函數?

Underscore manual

_.escape(字符串)轉義字符串用於插入HTML, 替換&,<,>,」,」,和/字符

+0

不知道這會做什麼/你如何提出我完全使用它。問題在於Backbone在引號中不能識別變量。會逃脫幫助嗎? – dshipper

1

。如果通過使用以下腳本將標記更改爲{{ - varName}},它將起作用:

_.templateSettings.escape = /\{\{-(.*?)\}\}/g 

在您的si tuation你將不得不更改模板爲:

script(type="text/template",id="waiting_call_template") 
    div(class="call-code") {{- channelId }} 
    div(style="display: inline-block; vertical-align: top; margin-right: 20px; width: 130px;") 
     div(class="statistic", title='{{- fullPage }}') {{- page }} 

來源:Underscore templating - changing token markers

0

只是未逃脫你的模板。使用下劃線'unescape'。在您的骨幹:

_.template($('#tmpl-following').html()),

變化

_.template(_.unescape($('#tmpl-following').html())),