【问题标题】:Angularjs - orderby property of objects in an arrayAngularjs - 数组中对象的 orderby 属性
【发布时间】:2015-12-27 09:31:39
【问题描述】:

我有一个对象数组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

【问题讨论】:

    标签: arrays angularjs javascript-objects angularjs-filter


    【解决方案1】:

    根据文档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;
    });
    

    【讨论】:

      【解决方案2】:

      这样试试

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2016-02-25
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2017-11-08
        • 2017-11-08
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多