小胡子 - 如何检测数组不为空? [英] Mustache - How to detect array is not empty?
本文介绍了小胡子 - 如何检测数组不为空?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我要实现与小胡子以下逻辑:
{{#如果users.length> 0}}
< UL>
{{#users}}
<立GT; {{}}< /李>
{{/用户}}
< / UL>
{{/如果}}//如。数据= {用户:['汤姆','杰里']}
我应该修改用户
结构,以满足需要?例如:
{{#hasUsers}}
< UL>
{{#users}}
<立GT; {{}}< /李>
{{/用户}}
< / UL>
{{/ hasUsers}}//如。数据= {hasUsers:true,则用户:['汤姆','杰里']}
解决方案
对不起,这可能是为时已晚。但我也有类似的要求,找到了一个更好的方式来做到这一点:
{{#users.length}}
< UL>
{{#users}}
<立GT; {{}}< /李>
{{/用户}}
< / UL>
{{/users.length}}
{{^ users.length}}
< P>没有用户< / P>
{{/users.length}}
工作样本这里: http://jsfiddle.net/eSvdb/
I want to implement the following logic with Mustache:
{{#if users.length > 0}}
<ul>
{{#users}}
<li>{{.}}</li>
{{/users}}
</ul>
{{/if}}
// eg. data = { users: ['Tom', 'Jerry'] }
Should I modify the users
structure to meet the need? For example:
{{#hasUsers}}
<ul>
{{#users}}
<li>{{.}}</li>
{{/users}}
</ul>
{{/hasUsers}}
// eg. data = { hasUsers: true, users: ['Tom', 'Jerry'] }
解决方案
Sorry, this may be too late. But I had similar requirement and found a better way to do this:
{{#users.length}}
<ul>
{{#users}}
<li>{{.}}</li>
{{/users}}
</ul>
{{/users.length}}
{{^users.length}}
<p>No Users</p>
{{/users.length}}
Working sample here: http://jsfiddle.net/eSvdb/
这篇关于小胡子 - 如何检测数组不为空?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文