meteor - Multiple Spacebar Conditional Operators -


क्या कम करने का कोई तरीका है

  {{# if arg1}} {{# अगर arg2}} // सामान {{/ if}} {{/ if}}  

सिर्फ एक ही है?

  {if # Arg1 arg2}} {{#if arg1 & amp; amp; Arg2}}  

उपर्युक्त दोनों काम नहीं करते।

स्पेसबर्स मूसा और हैंडलेबर्स के तर्क को कम-से-कम टेम्पलेट भाषाओं के रूप में जारी करते हैं यही कारण है कि टेम्पलेट के बजाय नियंत्रक में भी सरल तर्क भी रखा जाता है।

आप, हालांकि, जो तार्किक और करता है।

  & lt; टेम्पलेट नाम = "ifand" & gt; {{#if arg1}} {{#if arg2}} {{& gt; Template.contentBlock}} {{else}} {{& gt; Template.elseBlock}} {{/ if}} {{else}} {{& gt; Template.elseBlock}} {{/ if}} & lt; / template & gt;  

इस रूप में कॉल:

  {{ifand arg1 = "foo" arg2 = "bar"}} // सामान {{/ ifand}} < / Code> 

आप भी सीख सकते हैं।

सामान्य मामले ( और में तर्कों की एक मनमाना संख्या के बीच), आप एक वैश्विक टेम्पलेट सहायक:

  Template.registerHelper ('और', फ़ंक्शन) {var args = Array.prototype.slice.call (तर्क, 0, -1); // कुंजी बहिष्कृत = मान एल्ग्स var पैरामीटर = आर्गुमेंट्स [आर्गुमेंट्स। लांति - 1]; // कुंजी: मान आर्गुग्स रिटर्न _.ईvery (आर्ग्स, फंक्शन (आर्ग) {रिटर्न !! आरजी;});});  

इस रूप में कॉल करें:

  {{# if and 1 "foo" 3 'bar' param = "test"}} सच {{else}} झूठी {{/ if}}  

Comments

Popular posts from this blog

HTML/CSS - Automatically set height width from background image? -

php - Mysql Show Process - Sleep Commands and what to do -

list Class in C++ -