2014-02-14 48 views

回答

16

您可以使用下面的語法:

{{? it.name }} 
<div>Oh, I love your name, {{=it.name}}!</div> 
{{?? it.age === 0}} 
<div>Guess nobody named you yet!</div> 
{{?? it.age > 20}} 
<div>You're old!</div> 
{{??}} 
You are {{=it.age}} and still don't have a name? 
{{?}} 

上述被編譯到:

function anonymous(it /**/) 
{ 
    var out=''; 

    if(it.name) 
    { 
     out+='<div>Oh, I love your name, '+(it.name)+'!</div>'; 
    } 
    else if(it.age === 0) 
    { 
     out+='<div>Guess nobody named you yet!</div>'; 
    } 
    else if(it.age > 20) 
    { 
     out+='<div>You\'re old!</div>'; 
    } 
    else 
    { 
     out+='You are '+(it.age)+' and still don\'t have a name?'; 
    } 
    return out; 
} 

本質上說,只是不停地加入{{?? condition}}ü只要你得到{{?}}(塊的結尾)。

+0

感謝...幫助... –

+0

似乎是正確的,但在所有這些條件語句的性能之間的關係可能會造成混淆。你可能想編輯,以便你只是檢查單個屬性的各種可能性。 – yonas

1

你可以這樣說:

<!-- CONDITIONAL !--> 
 
<!-- if --> 
 
<div> 
 
    {{? it[0].firstName }} 
 
    {{=it[0].firstName }} 
 
    {{?}} 
 
</div> 
 

 
<!-- if/else if/else --> 
 
<div> 
 
    <!-- if --> 
 
    {{? it[0].lastName }} 
 
    <span>First name is set</span> 
 

 
    <!-- else if --> 
 
    {{?? it[0].zip}} 
 
    <span>You don't have a last name</span> 
 

 
    <!-- else if --> 
 
    {{?? it[0].firstName}} 
 
    <span>Your firstName is: {{=it[0].firstName}}</span> 
 

 
    <!-- else if end --> 
 
    {{??}} 
 
          
 
    <!-- else --> 
 
    <span>You didn't set your name</span> 
 
          
 
    <!-- if end --> 
 
    {{?}} 
 
</div>

+0

這是錯誤的:

0

這個圖像標籤是不正確:

\t 
 
<img src="{{=(user.absolutePath=='')?'img/user-shape.png':user.absolutePath;}}">

這是正確的:

  {{~it.userCollection[0].attributes.admin :user:index}} 
 
       <div class="team-content-user"> 
 
       <!-- if not null--> 
 
       {{?user.absolutePath}} 
 
        <img src="{{=user.absolutePath}}"> 
 
        <!-- if not (not null) --> 
 
        {{??!user.absolutePath}} 
 
        <img src="img/user-shape.png"> 
 
        {{??}} 
 
       {{?}} 
 
       {{=user.email}}</br> 
 

 
       </div> 
 
      {{~}}

+0

如果可能,請指出爲什麼引用的摘錄是不正確的 – stolli