我一直在阅读这些关于Spacebars的教程.
Understanding Spacebars by David Burles
Meteor’s Spacebars README on Github
Discover Meteor’s Spacebars secrets
我想我能理解得很好,但我遇到了这个问题
我有这样的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>
所以,就像你们看到我在主模板中调用2个模板,2个模板看起来像这样
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 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>
那么问题是什么?好吧,如果我们看一下模板Lunes和showPromos,我有一个Data-Panel =“panel”,但是当我将这个值包装在{{each}}标签上时,似乎数据面板不起作用,因为如果我使用,它工作的数据面板选择器外面的{{each}}标签,所以看起来它不工作似乎他们没有连接.
所以即时通讯询问是否有办法连接该值?已经尝试过辅助属性,比如第3个链接说,并且不起作用,属性助手看起来像这样
Template.main.helpers({ attributes: function () { return { dataPanel: "prueba",} } });
帮手mostrarLunes
Template.main.helpers({ 'mostrarLunes' : function(){ return Promociones.find({'Metadata.diaOferta' : { $in: ['Lunes'] } }); } });
解决方法
看起来没有设置数据上下文.尝试使用数据为其他模板创建模板助手(我不懂西班牙语,所以我假设这是你需要的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'] } }); } });
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。