0

我有一个大问题。我想对这样的数组进行排序:

 '0' ...
        '0' ...
            'id' => "XXXXX"
            'from' ...
                'name' => "XXXX"
                'id' => "XXXXXXXX"
            'story' => "XXXXXXXXXX"
        '1' ...
            'id' => "XXXXX"
            'from' ...
                'name' => "XXXX"
                'id' => "XXXXXXXX"
            'story' => "XXXXXXXXXX"
        '2' ...
            'id' => "XXXXX"
            'from' ...
                'name' => "XXXX"
                'id' => "XXXXXXXX"
            'story' => "XXXXXXXXXX"

我想按键 FROM-NAME 对数组进行排序。你能帮助我吗?

4

1 回答 1

3

试试这个:

yourarray.sort(function(a,b){
    return a.from.name<b.from.name ? -1 : 1;
});
于 2012-07-21T12:47:40.073 回答