2013-10-26 30 views
0

我第一次使用Google Closure模板。
我們可以在Google Closure模板中使用Bitwise運算符嗎?
我想用一些這樣的事:Google Closure模板按位運算符

{if $saleStatus.errors & $constant.displayValue} 
<div class="displaye"> 
<msg desc="user is banned"> 
User is Banned. 
</msg> 
</div>  
{/if} 

在這裏,我想使用位運算符,但我會拋出異常的語法錯誤。
或者有什麼方法我應該使用。可能包括js並在那裏做些什麼?

回答

1

按位AND不是Google Closure模板中支持的運算符。您應該在調用模板之前使用JavaScript對此進行評估,並將其作爲參數傳入。 See the list of supported operators.

例如,這樣的事情...

在JavaScript:

var err = saleStatus.errors & constant.displayValue; 
$(elem).html(namespace.myTemplate, { err: err }); 
在大豆/關閉

.... 

/** 
* Example ... 
* @param err The error 
*/ 
{template .myTemplate} 
    {if err} 
     <div class="displaye"> 
      <msg desc="user is banned"> 
       User is Banned. 
      </msg> 
     </div> 
    {/if} 
{/template} 

有關概念的更多信息,請參閱the documentation.

+0

它很好,當我只有一次,但如果我hav會發生什麼這在每個循環中都有。像{foreach saleStatus in saleStatuses}。在這種情況下,我有{saleStatus.errors}可能每次都有不同的值。 –

+0

考慮在渲染模板之前計算這些值。您可以通過循環使用saleStatuses並添加一個包含saleStatus.errors&constant.displayValue的新屬性 –