是有可能限制在AngularJs循环显示的项目的数目 [英] Is it possible to limit the number of displayed items in a loop in AngularJs
本文介绍了是有可能限制在AngularJs循环显示的项目的数目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有属于不同类别的类别和许多问题的清单。
I have a list of categories and many questions which belongs to different categories.
{
"id": 5,
"description": "Does your site have Facebook?",
"question_category_id": 3
}
{
"id": 1,
"name": "Network",
"description": "Network"
}
<table ng-repeat="c in categories">
<thead>
<tr>
<th>{{ c.id }}. {{ c.description }}</th>
</tr>
</thead>
<tbody ng-repeat="q in questions | filter: { question_category_id: c.id } : true">
<tr>
<td>{{q.description}}</td>
</tr>
</tbody>
</table>
这是code这显示下一个类别中的所有问题。
This is the code which displays all questions under a category.
但我用AngularJs要循环通过每个在一个类别下的类别,只显示1问题。
But I want to loop through each of the categories and only display 1 question under one category by using AngularJs.
这可能吗?
如果是的话,怎么样?
Is it possible ? If yes, how?
感谢您。
推荐答案
如果你真的想遍历问题
,那么你可以使用 $首页
。
If you really want to iterate over questions
, then you could use $index
.
<tbody
ng-repeat="q in questions | filter: { question_category_id: c.id } : true"
ng-show="$index == 0">
如果没有,但你仍然不想碰的JavaScript部分,then'd我会去解决这个使用
If not, but still you do not want to touch the JavaScript part, then'd I'd go around this using
<td>
{{ (questions | filter: { question_category_id: c.id } : true)[0].description }}
</td>
这篇关于是有可能限制在AngularJs循环显示的项目的数目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文