简体   繁体   English

如何让{{#each}}使用这些模板?

[英]How do I make {{#each}} work with these templates?

I have been reading these tutorials on Spacebars. 我一直在阅读这些关于Spacebars的教程。

Understanding Spacebars by David Burles 通过David Burles了解Spacebars

Meteor's Spacebars README on Github Meteor在Github上的Spacebars自述文件

Discover Meteor's Spacebars secrets 发现Meteor的Spacebars秘密

I think I can understand pretty good, but I am having this problem 我想我能理解得很好,但我遇到了这个问题

i have the main.html template like this 我有这样的main.html模板

<template name="main">
  <div class="container">   
<section id="bl-work-section">
    <div class="bl-box">
          <h4 class="sin">Próximo</h4>
          <h2  id="titulo1" class="sin"></h2>
          <h4 class="sin" id="sub1"></h4>
    </div>
        <div class="bl-content">
            <h2>Lunes 25 de Noviembre del 2014</h2> 

            {{#each mostrarLunes}}
            {{> Lunes}}
            {{/each}}
    <a></a>
    </div>    
        <span class="bl-icon bl-icon-close"></span>
</section>

<!-- Panel items for the works -->  
   <div class="bl-panel-items" id="bl-panel-work-items">
       {{#each mostrarLunes}}
            {{showPromos}}
       {{/each}}
    </div>                
        </div>
        </div><!-- /container -->       
</template>

So like you guys see im calling 2 templates inside main template and that 2 templates look like this 所以,就像你们看到我在主模板中调用2个模板,2个模板看起来像这样

Lunes.html Template Lunes.html模板

<template name="Lunes">
  <ul id="bl-work-items">           
               <li data-panel="panel">        
              <div class="oferta">
            <a href="#"> <h3>Promocion: {{metadata.nombrePromo}} </h3><br><small>Descripcion:{{metadata.descripcionPromo}}</small></a>
        </div></li><br><br> 
                        </ul>    
</template>

showPromos.html Template showPromos.html模板

<template name="showPromos">
  <div data-panel="panel">          
    <div>
              <h1>Estoy viendo esto en la segunda pagina </h1>
                            <h3>Nombre Promo {{metadata.nombrePromo}}</h3>
                            <p>Descripcion promo.{{metadata.descripcionPromo}}</p>
                        </div>               
                    </div>          
                    <nav>
                        <span class="bl-icon bl-icon-close"></span>
                    </nav>       
</template>

So what is the problem? 那么问题是什么? well if we look at the template Lunes and showPromos , i have a Data-Panel="panel" , but its seems like that data panel don't work when i wrap that value on the {{each}} tags, because if i use, that {{each}} tags outside the data-panel selector it works, so its seems like its not working seems like they don't have connection. 好吧,如果我们看一下模板LunesshowPromos ,我有一个Data-Panel =“panel” ,但是当我将这个值包装在{{each}}标签上时,似乎数据面板不起作用,因为如果我使用,它工作的数据面板选择器外面的{{each}}标签,所以看起来它不工作似乎他们没有连接。

so im asking if there is a way to connect that value? 所以即时通讯询问是否有办法连接该值? already try helper attributes like the 3rd link says, and don't work, the attributes helpers look like this 已经尝试过辅助属性,比如第3个链接说,并且不起作用,属性助手看起来像这样

Template.main.helpers({
  attributes: function () {
    return { 
      dataPanel: "prueba",
    }
  }
});

Helper mostrarLunes 帮手mostrarLunes

Template.main.helpers({
  'mostrarLunes' : function(){
    return Promociones.find({'metadata.diaOferta' : { $in: ['Lunes'] } });
  }
});

Looks like the data context isn't set. 看起来没有设置数据上下文。 Try creating a template helper for your other templates with the data (I don't understand Spanish so I'm assuming this is the MongoDB cursor you need... 尝试使用数据为其他模板创建模板助手(我不懂西班牙语,所以我假设这是你需要的MongoDB游标...

Templates.lunes.helpers({
  data: function() {
    return Promociones.find({'metadata.diaOferta' : { $in: ['Lunes'] } });
  }
});

Templates.showPromos.helpers({
  data: function() {
    return Promociones.find({'metadata.diaOferta' : { $in: ['Lunes'] } });
  }
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM