我是这个角度js的新手。我有这样的代码:
我有嵌套的ng-repeat(一个ng-repeat在另一个内)。我想通过动态选项安排内部列表的顺序。
ie:sort_option值来自$ scope变量动态获取。这将使所有内部ul列表按排序顺序排列。但我想在内部循环中只排序一个列表。
<ul>
<li ng-repeat='itemsli in mylists.lists'>
<ul>
<li ng-repeat="item in list | orderBy: sort_option | filter: {due_date_time : current_date_time}">
{{item.name}}
</li>
</ul>
</li>
</ul>
答案 0 :(得分:1)
更改这样的行,在过滤器的末尾添加: true
<li ng-repeat="item in list | orderBy: sort_option | filter: {due_date_time : current_date_time}: true ">
答案 1 :(得分:0)
我不确定我是否理解正确
但我创建了sample code,就像你的一样,看起来效果很好
列表是
$scope.firstLists = [{id: 2},{id: 1},{id: 3}];
$scope.secondLists = [{id: 2},{id: 1},{id: 3}];
与
<ul>
<li ng-repeat='itemsli in firstLists'>
<ul>
<li ng-repeat="item in secondLists | orderBy: 'id'">
{{item.id}} of {{itemsli.id}}
</li>
</ul>
</li>
</ul>
,结果是
1 of 2
2 of 2
3 of 2
1 of 1
2 of 1
3 of 1
1 of 3
2 of 3
3 of 3
答案 2 :(得分:0)
其实我有代码:
<ul>
<li ng-repeat='itemsli in mylists.lists'>
<md-button ng-click="sortby_cards('vote')">Sort by votes</md-button>
<md-button ng-click="sortby_cards('attachment_count')">Sort by Attachments
</md-button>
<ul>
<li ng-repeat="item in list | orderBy: sort_option | filter: {due_date_time : current_date_time}">
{{item.name}}
</li>
</ul>
</li>
</ul>
在控制器中:
$scope.sortby_cards = function(sort_value){
console.log(sort_value);
$scope.sort_option = sort_value;
}
当我点击按钮按投票排序按特定内部列表按其投票顺序排序时。 我想你现在明白了我的问题。
答案 3 :(得分:0)
我得到了回答:
<ul>
<li ng-repeat='lists in mylists.lists'>
<md-button ng-click="sortby_cards('vote', lists)">Sort by votes</md-button>
<md-button ng-click="sortby_cards('attachment_count', lists)">Sort by Attachments
</md-button>
<ul>
<li ng-repeat="item in list | orderBy: list.sort_option | filter: {due_date_time : current_date_time}">
{{item.name}}
</li>
</ul>
</li>
</ul>
在控制器中:
$scope.sortby_cards = function(sort_value,list){
$scope.sort_option = sort_value;
$scope.sort_index_val = index_val;
list.sort_option = sort_value;
}
这是正确的答案。
感谢Farzad Salimi Jazi。
答案 4 :(得分:0)
你在寻找这种嵌套的ng-repeat吗?
var app = angular.module('soApp', []);
app.controller('soController', function ($scope) {
$scope.firstName = "John";
$scope.lastName = "Doe";
$scope.sortby_cards = function (sort_value) {
console.log(sort_value);
$scope.sort_option = sort_value;
};
$scope.firstLists = [{name: "def", vote: 2}, {name: "ret", vote: 1}, {name: "ghj", vote: 3}];
$scope.secondLists = [{name: "pqr", vote: 2, attachment_count: 1},
{name: "abc", vote: 1, attachment_count: 3},
{name: "xyz", vote: 3, attachment_count: 2}];
});