下划线组使json对象丢失

时间:2015-05-04 01:40:16

标签: json group-by underscore.js grouping

我从服务器端获取了一个json对象,包含了所有嵌套数据。但是在我使用下划线groupby根据属性(比如startTime here)对我的对象进行分组后,返回数组正在被更改(我的嵌套数据被遗漏并被替换为“[object]”)。

在分组之前:

var objs = 
[{  id: '551de304e4b',
category: 'Restaurant',
title: 'Hurricane',
location: 'Darling harbor',
checkListItems: [ [Object], [Object], [Object], [Object] ],
startTime: Wed Dec 02 2014 08:00:00 GMT+0800 (CST),
detailRestaurant: 
   { id: '551de304e4b',
     name: 'Hurricane',
     telphone: '020-3455555' } 
},
{   id: '551de301e4b',
category: 'Restaurant',
title: 'The Grill',
location: 'Darling harbor',
checkListItems: [ [Object], [Object], [Object], [Object] ],
startTime: Wed Dec 03 2014 08:00:00 GMT+0800 (CST),
detailRestaurant: 
   { id: '551de301e4b',
     name: 'The Grill',
     telphone: '020-0009998' } 
}];

分组后:

{'1417449600000': 
   [ { id: '551de304e4b',
       category: 'Restaurant',
       title: 'Restaurant',
       location: 'Hurricane',
       checkListItems: [Object],
       startTime: Wed Dec 02 2014 08:00:00 GMT+0800 (CST),
       detailRestaurant : [Object] } ],
 '1417536000000': 
   [ { id: '551de304e4b',
       category: 'Restaurant',
       title: 'Restaurant',
       location: 'Hurricane',
       checkListItems: [Object],
       startTime: Wed Dec 03 2014 08:00:00 GMT+0800 (CST),
       detailRestaurant : [Object] } ]
}

我的groupby函数如下所示:

function groupByStartTime (objs){
    var objs = _.sortBy(objs, function(obj){
        return obj.startTime;
    });
    // objs in here is correct with all nested data
    var groups = _.groupBy(objs, function(obj){
        return obj.startTime;
    });
    // nested data within groups here is being folded 
    return groups;
}

0 个答案:

没有答案