2014-12-23 38 views
1

我有這樣的幫手使用條件語句裏面{{每個}}循環

Template.clientesPromo.helpers({ 
    'mostrarPromosCliente' : function(){ 
    return Promociones.find({'metadata.modalCliente' : Session.get("val") }); 
    } 
}) 

,並用它這樣

<template name="clientesPromo"> 
{{#each mostrarPromosCliente}} 
<p style="color:#666; display: inline-block;">{{metadata.diaOferta}}</p> 
{{/each}} 
</template> 

這工作就返回例如週一,Thuesday等,但我想做下一個

如果diaOferta等於星期一,星期二等(一週中的7天)幫助者返回「周的所有日子」而不是星期一,星期二等,

與metadata.diaOferta其天

數組名稱上蒙戈的數據其有沒有辦法做到這一點?

回答

4
<template name="clientesPromo"> 
{{#each mostrarPromosCliente}} 
<p style="color:#666; display: inline-block;">{{getValue}}</p> 
{{/each}} 
</template> 

創建另一個輔助

Template.clientesPromo.helpers({ 
    'mostrarPromosCliente' : function(){ 
    return Promociones.find({'metadata.modalCliente' : Session.get("val") }); 
    }, 
    'getValue':function(){ 
     //here you can access metadata.modalCliente using **this.metadata.modalCliente** 
     var days=this.metadata.modalCliente; 

     //logic to checkj whether all days exists or not 
     if(allDays){ 
     return "all days of the week" 
     } 
     else{ 
     return this.metadata.modalCliente; 
     } 

    } 
}) 
+0

它工作夥伴坦克如果我使用(days.length> 6){}; – Ethaan