NG-重复对数组的数组排序依据子数组索引 [英] ng-repeat on array of arrays, orderBy subarray index

查看:282
本文介绍了NG-重复对数组的数组排序依据子数组索引的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

让我们说我有这个对象:

Let's say I have this object:

var rows = [
    [1, 2, 3, 4],
    [11, 222, 3333, 4444]
];

由于和这个模板:

Given that, and this template:

<tr ng-repeat="row in rows | orderBy ????">
    <td ng-repeat="cell in row">{{ cell }}</td>
</tr>

...我怎么能订购 NG-重复通过指数 1 给定的元素)?

...how can I order an ng-repeat by the second "column" of each row (the value at index 1 of the given row element)?

我是纠正角度不支持这种情况下&MDASH;而无需编写自定义排序函数? (我只是原型,因此,使用 NG-INIT 来定义我的范围变量代替创建一个控制器。)

Am I correct that Angular does not support this case—without having to write a custom sort function? (I'm just prototyping, so using ng-init to define my scope variables instead of creating a controller.)

推荐答案

其实它的作用。您可以创建自定义的功能顺序。

Actually it does. You can create custom order by functions.

http://plnkr.co/edit/f6hCbHcLkrjyTODvDWjM?p=$p$ PVIEW

<div ng-repeat="row in rows | orderBy:secondIndex">
    {{row}}
</div>

//In controller
$scope.secondIndex = function(arr){
    return arr[1];
}

这篇关于NG-重复对数组的数组排序依据子数组索引的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆