underscore.js

Reorder a JSON collection

僤鯓⒐⒋嵵緔 提交于 2020-01-03 05:17:48
问题 I have a JSON array fetch from my server which looks like : [ {name: "Web Design", id: "27", month_n: "1", data: "68.00"}, {name: "Web Design", id: "27", month_n: "2", data: "56.00"} , {name: "Homework", id: "4", month_n: "2", data: "15.00"} , {name: "Gaming", id: "12", month_n: "2", data: "5.00"} ] On the client side, I want to reorder this to have something similar to : [{name: "Web Design", data:[68.00,56.00]}, {name:"Homework", data:[0,15]} and so on... Where the "data" value is grouped

Reorder a JSON collection

二次信任 提交于 2020-01-03 05:17:07
问题 I have a JSON array fetch from my server which looks like : [ {name: "Web Design", id: "27", month_n: "1", data: "68.00"}, {name: "Web Design", id: "27", month_n: "2", data: "56.00"} , {name: "Homework", id: "4", month_n: "2", data: "15.00"} , {name: "Gaming", id: "12", month_n: "2", data: "5.00"} ] On the client side, I want to reorder this to have something similar to : [{name: "Web Design", data:[68.00,56.00]}, {name:"Homework", data:[0,15]} and so on... Where the "data" value is grouped

Reorder a JSON collection

和自甴很熟 提交于 2020-01-03 05:17:06
问题 I have a JSON array fetch from my server which looks like : [ {name: "Web Design", id: "27", month_n: "1", data: "68.00"}, {name: "Web Design", id: "27", month_n: "2", data: "56.00"} , {name: "Homework", id: "4", month_n: "2", data: "15.00"} , {name: "Gaming", id: "12", month_n: "2", data: "5.00"} ] On the client side, I want to reorder this to have something similar to : [{name: "Web Design", data:[68.00,56.00]}, {name:"Homework", data:[0,15]} and so on... Where the "data" value is grouped

Node.js - dependant API request calls using async.waterfall and merge JSON response with underscore.extend

我的梦境 提交于 2020-01-03 04:46:30
问题 Okay, there is quite a bit happening here but I tried to isolate the issue as much as possible. In my node.js Express project, I'm making two API request calls that the second call is dependant on the first. To make this task easier, I'm using waterfall method from async module. In getVideoDetails function, I put the second API request in loop with the videoId retreived from the first response to get video data. The problem currently I have is that, var extended only gives me body value while

flatten javascript array of objects

这一生的挚爱 提交于 2020-01-02 22:42:36
问题 I have an array of object with hierarchical structure, something like this: [ {name: 'ParentOne', children: [ {name: 'ParentOneChildOne'}, {name: 'ParentOneChildTwo', children: [ {name: 'ParentOneChildTwoGrandChildOne'}, ]}, ]}, {name: 'ParentTwo', children: [ {name: 'ParentTwoChildOne', children: [ {name: 'ParentTwoChildOneGrandChildOne'}, {name: 'ParentTwoChildOneGrandChildTwo'} ]}, {name: 'ParentTwoChildTwo'} ]} ]; I want to flatten it: [ {name: 'ParentOne'}, {name: 'ParentOneChildOne'},

flatten javascript array of objects

怎甘沉沦 提交于 2020-01-02 22:42:10
问题 I have an array of object with hierarchical structure, something like this: [ {name: 'ParentOne', children: [ {name: 'ParentOneChildOne'}, {name: 'ParentOneChildTwo', children: [ {name: 'ParentOneChildTwoGrandChildOne'}, ]}, ]}, {name: 'ParentTwo', children: [ {name: 'ParentTwoChildOne', children: [ {name: 'ParentTwoChildOneGrandChildOne'}, {name: 'ParentTwoChildOneGrandChildTwo'} ]}, {name: 'ParentTwoChildTwo'} ]} ]; I want to flatten it: [ {name: 'ParentOne'}, {name: 'ParentOneChildOne'},

flatten javascript array of objects

岁酱吖の 提交于 2020-01-02 22:42:08
问题 I have an array of object with hierarchical structure, something like this: [ {name: 'ParentOne', children: [ {name: 'ParentOneChildOne'}, {name: 'ParentOneChildTwo', children: [ {name: 'ParentOneChildTwoGrandChildOne'}, ]}, ]}, {name: 'ParentTwo', children: [ {name: 'ParentTwoChildOne', children: [ {name: 'ParentTwoChildOneGrandChildOne'}, {name: 'ParentTwoChildOneGrandChildTwo'} ]}, {name: 'ParentTwoChildTwo'} ]} ]; I want to flatten it: [ {name: 'ParentOne'}, {name: 'ParentOneChildOne'},

Merge array of objects with underscore

家住魔仙堡 提交于 2020-01-02 21:57:20
问题 I have array of objects like this. And they have duplicated property 'contactName' values [ { categoryId:1 categoryName:"Default" contactId:141 contactName:"Anonymous" name:"Mobile" value:"+4417087654" }, { categoryId:1 categoryName:"Default" contactId:325 contactName:"Anonymous" name:"Email" value:"test2@gmail.com" }, { categoryId:1 categoryName:"Default" contactId:333 contactName:"Anonymous" name:"Email" value:"ivdtest@test.com" } ] I want to merge them in one object by the name of property

Convert array of objects to object of arrays using lodash

為{幸葍}努か 提交于 2020-01-02 11:14:04
问题 The title is a little bit confusing but I essentially want to convert this: [ {a: 1, b: 2, c:3}, {a: 4, b: 5, c:6}, {a: 7, b: 8, c:9} ] into: { a: [1,4,7], b: [2,5,8], c: [3,6,9] } using lodash (requirement). Any ideas??? 回答1: Here's a solution using lodash that maps across the keys and plucks the values for each key from the data before finally using _.zipOobject to build the result. var keys = _.keys(data[0]); var result = _.zipObject(keys, _.map(keys, key => _.map(data, key))); 回答2: Look

Use SerializeJSON to return an array of structs instead of JSON object with COLUMNS and DATA nodes?

不想你离开。 提交于 2020-01-02 10:28:10
问题 I am building a Railo app which deals with a lot of JSON data sent back and forth via Ajax. I've identified an opportunity to optimize its performance, but I'd like to hear some advice from the community before I tackle it. Here is a good example of the situation. I have an action on the server that queries a set of bid responses, serializes them to JSON, then returns them to my javascript on the front end, which then parses and renders some HTML. The format in which Railo returns the JSON is