Angularjs - 数组中对象的排序 属性

Angularjs - orderby property of objects in an array

我有一个对象数组 matchedProfiles,我正在尝试按 属性 中的值对这些对象进行排序。

matched profiles = [ 

{
common: Array[1],
match: 8.333333333333329,
score1: Array[1],
score2: Array[1],
user1ID: "1116145178404907",
user2ID: "1710007182568600"
}, 

{
common: Array[1],
match: 25,
score1: Array[1],
score2: Array[1],
user1ID: "170401213316838",
user2ID: "1710007182568600"
}

]

我试着订购这个数组

var sortedMP = $filter('orderBy')(matchedProfiles, match);

但我在控制台日志中收到错误

Uncaught ReferenceError: match is not defined

这样试试

var sortedMP = $filter('orderBy')(matchedProfiles, 'match');

根据文档 https://docs.angularjs.org/api/ng/filter/orderBy 您可以将表达式作为字符串传递 'match'

var sortedMP = $filter('orderBy')(matchedProfiles, 'match');

或函数

var sortedMP = $filter('orderBy')(matchedProfiles, function(profile) {
    return profile.match;
});