简体   繁体   English

使用Lodash MapReduce更新集合的集合

[英]Update collection of collection using lodash mapreduce

I have following collection which i need to send it to datatable and it won't accept collection of collection. 我有以下收集,我需要将其发送到数据表,并且它将不接受收集。 So i need to flatten my structure and trying with lodash without much success. 因此,我需要弄平结构并尝试使用lodash,但收效不大。

My initial collection 我最初的收藏

 { "campaigns": [ { "name": "1st Campaign", "campaignType": "Test Campaign", "startDate": "2019/04/03", "endDate": "2019/04/30", "price": 1, "books": [ { "title": "\\"If They Move . . . Kill 'Em!\\"", "bookdata": { "batch": 2 } }, { "title": "!Click Song", "bookdata": { "batch": null } } ] }, { "name": "2nd cam", "campaignType": "test type", "startDate": "2019/04/10", "endDate": "2019/04/10", "price": 2.99, "retailers": null, "comments": null, "books": [ { "title": "\\"Johnny, We Hardly Knew Ye\\"", "bookdata": { "batch": null } }, { "title": "'A Very Fine Commander'", "bookdata": { "batch": 2 } } ] } ] } 

For each campaign i need structure like following where books title is comma separated for each books under campaign 对于每个营销活动,我都需要像下面这样的结构,其中,营销活动中的每本图书的书名均以逗号分隔

  { "campaigns": [ { "name": "1st Campaign", "campaignType": "Test Campaign", "startDate": "2019/04/03", "endDate": "2019/04/30", "price": 1, "booksname": "\\"If They Move . . . Kill 'Em!\\"","!Click Song" "books": [ { "title": "\\"If They Move . . . Kill 'Em!\\"", "bookdata": { "batch": 2 } }, { "title": "!Click Song", "bookdata": { "batch": null } } ] }, { "name": "2nd cam", "campaignType": "test type", "startDate": "2019/04/10", "endDate": "2019/04/10", "price": 2.99, "retailers": null, "comments": null, "books": [ { "title": "\\"Johnny, We Hardly Knew Ye\\"", "bookdata": { "batch": null } }, { "title": "'A Very Fine Commander'", "bookdata": { "batch": 2 } } ] } ] } 

I was able to do it using 我能够使用

                        data.campaigns.map((item) => {
                            item.Booksname = _.map(item.books, 'title').join(',');
                        })

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM