我有一組顯示一定數(shù)量的磁貼,具體取決于用戶選擇的選項(xiàng)。我現(xiàn)在想通過顯示的任何數(shù)字來實(shí)現(xiàn)排序。下面的代碼顯示了我是如何實(shí)現(xiàn)的(通過在父卡范圍內(nèi)獲取/設(shè)置一個(gè)值)。現(xiàn)在,由于orderBy函數(shù)采用一個(gè)字符串,因此我嘗試在卡范圍內(nèi)設(shè)置一個(gè)名為curOptionValue的變量并以此進(jìn)行排序,但它似乎不起作用。因此,問題就變成了,如何創(chuàng)建自定義排序功能?<div ng-controller="aggViewport" ><div class="btn-group" > <button ng-click="setOption(opt.name)" ng-repeat="opt in optList" class="btn active">{{opt.name}}</button></div><div id="container" iso-grid width="500px" height="500px"> <div ng-repeat="card in cards" class="item {{card.class}}" ng-controller="aggCardController"> <table width="100%"> <tr> <td align="center"> <h4>{{card.name}}</h4> </td> </tr> <tr> <td align="center"><h2>{{getOption()}}</h2></td> </tr> </table> </div></div>和控制器:module.controller('aggViewport',['$scope','$location',function($scope,$location) { $scope.cards = [ {name: card1, values: {opt1: 9, opt2: 10}}, {name: card1, values: {opt1: 9, opt2: 10}} ]; $scope.option = "opt1"; $scope.setOption = function(val){ $scope.option = val; }}]);module.controller('aggCardController',['$scope',function($scope){ $scope.getOption = function(){ return $scope.card.values[$scope.option]; }}]);
3 回答

桃花長(zhǎng)相依
TA貢獻(xiàn)1860條經(jīng)驗(yàn) 獲得超8個(gè)贊
要將方向與orderBy函數(shù)一起包括:
ng-repeat="card in cards | orderBy:myOrderbyFunction():defaultSortDirection"
哪里
defaultSortDirection = 0; // 0 = Ascending, 1 = Descending
- 3 回答
- 0 關(guān)注
- 1341 瀏覽
添加回答
舉報(bào)
0/150
提交
取消