我的對象是這樣的:按訂單
students = {name: 'Aa_Student', class: 'A_Class'},
{name: 'Ab_Student', class: 'A_Class'},
{name: 'Ac_Student', class: 'B_Class'},
{name: 'Ba_Student', class: 'B_Class'},
{name: 'Bb_Student', class: 'C_Class'},
{name: 'Bc_Student', class: 'C_Class'}
比方說,學生對象洗牌。我用ng-repeat顯示數據。我想按自定義順序排序對象。
例如,我要顯示這樣的數據:
Name Class
-----------------------------
Ac_Student B_Class
Ba_Student B_Class
Aa_Student A_Class
Ab_Student A_Class
Bb_Student C_Class
Bc_Student C_Class
所以基本上,我想通過學生的班級訂購,但它B_Class至上,然後A_Class,然後C_Class。另外,我想按學生的姓名按字母順序排列。我怎樣才能做到這一點?
HTML:
<table>
<tr ng-repeat="student in students | orderBy:customOrder">
...
</tr>
</table>
控制器:
$scope.customOrder = function(student) {
$scope.students = $filter('orderBy')(student, function() {
});
};
有兩種方法可以做到這一點(1)自定義過濾器(2)短數據在控制器級 – dhavalcengg
@dhavalcengg所以我需要使用過濾器? –
注意'$ scope.studens'中的拼寫錯誤(缺少t) – Gamb