2014-02-14 51 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