把手只显示前三项 [英] Handlebars showing only first three items

查看:74
本文介绍了把手只显示前三项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个广泛的新闻源(JSON),但我只需要在主页上向用户显示前三个新闻。有没有办法从第四个开始丢弃?
类似于:

I have an extensive news source (JSON), but I need to show only first three news to the user at home page. Is there a way to discard from the fourth onwards? Something like:

{{#each news}}
  {{ if index <= 3 }}
    <h3>{{title}} - {{date}}</h3>
    <p>{{post}}</p>
  {{/if}}
{{/each}}

它可能只与Handlebars或我需要使用Javascript?

Is it possible with Handlebars only or do I need to use Javascript?

推荐答案

您将需要使用Handlebar帮手,处理酒吧不做这种类型的条件检查。

you are going to need to use a Handlebar helper, handle bars does not do this type of conditional checking.

    Handlebars.registerHelper('arrayCheck', function (newsArray) {
        //Logic
    });

这篇关于把手只显示前三项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆