使用Angular排序到单独的列表中
Sorting into separate lists with Angular
我是角度和编程的新手,需要一些指导和帮助学习。我有一个html页面,有5个选项卡,"谁"、"什么"、"哪里"、"何时"answers"事件"。我有以下代码。如何获取控制器中的json类别条目,并将它们分离到与其相关的html选项卡中?我感谢你的帮助。
//html
<div id="chartsContainer" class="row">
<div class="col-xs-12">
<div id="" class="row">
<h3 class="pull-left" style="color:white">CHARTS</h3>
<form ng-submit="filterCharts()" class="pull-right">
<!-- Single button -->
<div class="btn-group">
<button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown">
all <span class="caret"></span>
</button>
<ul class="dropdown-menu" role="menu">
<li><a href="#">Used</a></li>
<li><a href="#">Unused</a></li>
</ul>
</div>
</form>
</div>
<div id="tabMasterContainer" ng-controller="TabsDemoCtrl">
<tabset vertical="false" type="navType">
<tab heading="Who">
<a ng-click="groupBy( 'category' )">Category</a>
<div id="chartsList" class="row">
<div id="" class="col-md-3" style="background-color:blue; height:100px; margin: 10px;" ng-repeat="chart in charts">
<p><i class="fa {{chart.icon}} fa-2x" style="color:white"></i></p>
<p style="color:white"> {{chart.description}} </p>
</div>
</div>
</tab>
<tab heading="What">
<div id="tabContainer">
<div id="" class="col-md-3" style="background-color:blue; height:100px; margin: 10px;" ng-repeat="chart in charts">
<p><i class="fa {{chart.icon}} fa-2x" style="color:white"></i></p>
<p style="color:white"> {{chart.description}} </p>
</div>
</div>
</tab>
<tab heading="When">
<div id="tabContainer">
<div id="" class="col-md-3" style="background-color:blue; height:100px; margin: 10px;" ng-repeat="chart in charts">
<p><i class="fa {{chart.icon}} fa-2x" style="color:white"></i></p>
<p style="color:white"> {{chart.description}} </p>
</div>
</div>
</tab>
<tab heading="Where">
<div id="tabContainer">
<div id="" class="col-md-3" style="background-color:blue; height:100px; margin: 10px;" ng-repeat="chart in charts">
<p><i class="fa {{chart.icon}} fa-2x" style="color:white"></i></p>
<p style="color:white"> {{chart.description}} </p>
</div>
</div>
</tab>
<tab heading="Events">
<div id="tabContainer">
<div id="" class="col-md-3" style="background-color:blue; height:100px; margin: 10px;" ng-repeat="chart in charts">
<p><i class="fa {{chart.icon}} fa-2x" style="color:white"></i></p>
<p style="color:white"> {{chart.description}} </p>
</div>
</div>
</tab>
</tabset>
</div>
</div>
</div>
$scope.charts = [
{ id : 1, description: "Date Range", icon : "fa-camera-retro", category : "When"},
{ id : 2, description: "Time of Day", icon : "fa-cog", category : "When"},
{ id : 3, description: "Day of Week", icon : "fa-bar-chart-o", category : "When"},
{ id : 4, description: "Age Range", icon : "fa-wrench", category : "Who"},
{ id : 5, description: "who foo", icon : "fa-wrench", category : "Who"},
{ id : 6, description: "what foo", icon : "fa-wrench", category : "What"},
{ id : 7, description: "what foo", icon : "fa-wrench", category : "What"},
{ id : 8, description: "where foo", icon : "fa-wrench", category : "Where"},
{ id : 9, description: "where foo", icon : "fa-wrench", category : "Where"},
{ id : 10, description: "basketball foo", icon : "fa-wrench", category : "Events"},
{ id : 11, description: "Doctor Who Foo", icon : "fa-wrench", category : "Events"},
{ id : 12, description: "You foo", icon : "fa-wrench", category : "Who"},
{ id : 13, description: "Boo foo", icon : "fa-wrench", category : "Events"},
{ id : 14, description: "da bar", icon : "fa-rocket", category : "Where"}
]
我知道我需要迭代json,所以我写了这个
function chartFinder(chartArray, id){
for (var i = 0; i < chartArray.length; ++i) {
if(id==chartArray[i].key)
return id[i].value;
}
};
一个简单的方法。对于每个类别,请执行以下操作。添加一个过滤器,它会自动为您执行此操作。
ng-repeat="chart in charts|filter:{category: 'Where'}"
相关文章:
- (取消)使用单独的复选框激活复选框列表
- Codrops页面转换.如何创建单独的按钮,而不是列表项目的效果
- 使用Angular排序到单独的列表中
- Vue.js"track-by-$index”;,如何单独呈现列表项
- 使用php创建的下拉列表中的选择单独填充文本区域
- 角度过滤器ng重复到单独的列表中
- 尝试将长列表排序为单独的列
- 将单个 json 拆分为单独的列表
- 使用 C# MVC 将值列表放入单独的文本框中
- 如何在C# MVC的VIew中将列表数组拆分为单独的数组
- 如何制作一个项目列表,可以使用 Angular JS 单独切换
- 根据一个子jQuery单独隐藏下拉列表
- 分开一个段落列表,给每个单词单独的CSS
- 如何以大写字母单独显示下拉列表的选定值
- 嵌套列表-在单独的一行上显示每个ul级别
- 使用jquery填充UL列表,但不调用单独的JavaScript函数
- 如何将参数的字符串列表传递给函数,并将它们作为单独的参数分配
- React / Redux—假设我们有两个单独的待办事项列表,已完成的和未完成的
- 使用jQuery在单独的无序列表中查找具有匹配类名的列表项
- 使用jQuery或CSS在特定位置将链接的ul列表拆分为单独的列