2012-02-25 35 views
1

我一直在使用handlebars.js進行javascript視圖,但已經碰到了它的牆。我需要條件支持,而且我似乎沒有做任何工作。帶有條件支持的Javascript模板引擎

我有下面的代碼塊:

<select id="status" name="status"> 
    {{#each statuses}} 
     <option value="{{ this }}"{{#equals userGroup this userGroup.status}} selected="selected"{{/equals}}>{{ this }}</option> 
    {{/each}} 
</select> 

我創建了一個叫做幫手等於但它似乎像變userGroup表示不可用的每個範圍內時。

有誰知道任何JavaScript模板引擎支持條件與if語句來支持這種功能(或如何在handlebars.js中)?

+0

underscore.js中的模板引擎提供了一個類似於ERB的模板方案,其中包含循環和if語句。它基本上是在線編譯Javascript。 – 2012-02-25 17:20:18

+0

手柄上的{{#if}}怎麼樣? – Pointy 2012-02-25 17:36:06

+0

@Pointy:Handlebars {{#if}}不支持像{{#if this == userGroup.status}} ... {{/ if}}這樣的條件。 – ryanzec 2012-02-25 17:41:42

回答

0

基於我原來的問題中的評論,我將與下劃線模板引擎(我已經用它來反其他事情)。