【发布时间】:2019-03-29 10:24:39
【问题描述】:
我正在创建一个带有标签的博客,每个博客条目可以有多个标签,可以过滤这些标签以显示选择了相同标签的博客条目。
我的问题在于,当我过滤结果时,我不确定如何将标签(或关键字)作为参数发送到另一个车把助手,所以我可以只显示具有相同标签的博客条目。
此代码从所有博客条目中获取所有标签:
<h4 class="white-color remove-margin">Tags:
{{#blog}}
{{#joinTags this}}
{{#each this}}
<a class="badge bg-light-blue" onclick="filterBlogEntries('{{this}}')">#{{this}}</a>
{{/each}}
{{/joinTags}}
{{/blog}}
</h4>
filterBlogEntries 现在什么都不做,只打印发送的参数。那一个参数是我需要过滤所有博客条目的参数。
到目前为止,我列出了所有这样的博客文章:
{{#blog}}
{{#each_upto this 6}}
<article>
<li class="blog-list__item">
<div class="blog-entry">
<img class="blog-entry__img" src="{{blog_entry.blog_img}}">
<h4 class="blog-tag">
{{#each blog_entry.blog_tag}}
<span class="badge bg-light-blue">#{{this}}</span>
{{/each}}
</h4>
<h3 class="highlight center-text remove-margin">{{blog_entry.blog_title}}</h3>
<h4 class="center-text remove-margin">{{blog_entry.blog_subtitle}}</h4>
<a class="blue-color bold center-text" onclick="showEntry( '{{blog_entry.blog_img}}','{{blog_entry.blog_tag}}','{{blog_entry.blog_title}}', '{{blog_entry.blog_subtitle}}','{{blog_entry.blog_text}}')">Ver más</a>
</div>
</li>
</article>
{{/each_upto}}
{{/blog}}
现在,我的问题是,通过函数 filterBlogEntries(),我如何发送用户选择的标签以按标签过滤博客条目?
【问题讨论】:
标签: javascript handlebars.js enduro.js