仅使用Mustache显示列表中的第一项 [英] only show the first item in list using Mustache
本文介绍了仅使用Mustache显示列表中的第一项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用胡子模板引擎,我只想显示长列表中的第一项,但似乎无法找到这样做的文档?
I am using the mustache template engine and I only want to display the first item in a long list but cant seem to find the docs for doing so?
如果我使用:
{{# links}}<a href="{{& url}}">{{& title }}</a>{{/ links}}
我得到了所有的链接,但是我只想要显示第一个,听起来很简单,但我找不到任何文档。
i get all of the links, however i only want the first one to be displayed, sounds easy but I cant find any docs on this.
推荐答案
此解决方案是使用新版本的Mustache.js(仅):
This solution is working with the new version of Mustache.js (only):
mustache.render("{{a.0}}", {a: ['hi','world']})
=> 'hi'
这篇关于仅使用Mustache显示列表中的第一项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文