2016-01-31 5 views
5

में प्रत्येक नेस्ट करता है:क्यों अपेक्षा के अनुरूप एक ओर जहां यह प्रदान की गई है टेम्पलेट उत्पादन कुछ भी नहीं

{{#each Items}} // a collection 
    {{title}} 
{{/each}} 
{{#each types}} // another ollection 
    {{refId}} 
{{/each}} 

अगर मैं इसे एक साथ रखा:

{{#each Items}} 
    {{title}} 
    {{#each types}} 
    {{refId}} 
    {{/each}} 
{{/each}} 

#each types खाली है।

टेम्पलेट सहायकों:

Template.menuItems.helpers({ 
    restMenuItems: function() { 
     return RestMenuItems.find({restRefId: this._id}, {sort:Template.instance().sort.get()}); 
    }, 
    restMenuSideItems: function() { 
     return RestMenuSideItems.find({restRefId: this._id},   {sort:Template.instance().sort.get()}); 
    } 
}); 

Template.menuItems.onCreated(function(){ 
    this.subscribe('restMenuItems'); 
    this.subscribe('restMenuSideItems'); 
}); 

और टेम्पलेट कोड के कुछ:

{{#each restMenuItems}} 
    <div> 
    <select class="list-group select_side_addons"> 
     {{#each restMenuSideItems}} 
     <option>{{restRefId}}</option> 
     {{/each}} 
    </select> 
    </div> 
{{/each}} 

यहां तक ​​कि जब {{#each ../restMenuSideItems}} द्वारा {{#each restMenuSideItems}} की जगह, कुछ भी नहीं दिखाई देता है।

क्या गलत है?

उत्तर

3

क्योंकि #each खंड वर्तमान आइटम में डेटा संदर्भ को बदलता है।

यदि आप Items में से प्रत्येक के अंदर types की एक सूची चाहते हैं, तो आप .. का उपयोग कर मूल डेटा संदर्भ प्राप्त कर सकते हैं।

{{#each Items}} 
    {{title}} 
    {{#each ../types}} 
    {{refId}} 
    {{/each}} 
{{/each}} 

तो types एक टेम्पलेट सहायक है, तो आप इसे करने के लिए एक तर्क के रूप माता पिता संदर्भ पारित कर सकते हैं:

{{#each Items}} 
    {{title}} 
    {{#each types ..}} 
    {{refId}} 
    {{/each}} 
{{/each}} 

और प्रयोग

तो types माता पिता संदर्भ की एक विशेषता है आपकी क्वेरी के लिए संदर्भ।

Template.myTemplate.helpers({ 

    types: function(parent) { 
    // you now have the parent context here. 
    // use parent._id etc. where you used this._id in the 
    // "flat" version. 
    } 
}); 
+0

धन्यवाद, लेकिन यह अभी भी वही है। –

+0

अजीब, यह काम करना चाहिए। क्या आप अधिक कोड प्रदान कर सकते हैं (उदा।, आपके सहायक और अधिक संपूर्ण टेम्पलेट कोड)? 'आइटम 'और' प्रकार 'कहां से आते हैं? – MasterAM

+0

बस किया। @MasterAM –

संबंधित मुद्दे