javascript - how to get a desired order of this java script object? -
lets see, have jquery parsed json object (but bigger):
[ {answered: 0, caller: 4, callid: 4, expired: 0, groupid: 2, location: "jubin", name: "vahid", personid: 3, presense: 1367323732, response: null, text: null, time: 1367336754, type: 0}, {answered: 0, caller: 6, callid: 5, expired: 0, groupid: 2, location: "jubin", name: "vahid", personid: 3, presense: 1367323732, response: null, text: null, time: 1367336766, type: 0}, {answered: 0, caller: 4, callid: 4, expired: 0, groupid: 2, location: "jubin", name: "reza", personid: 1, presense: 1367392633, response: null, text: null, time: 1367336754, type: 0}, {answered: 0, caller: 6, callid: 5, expired: 0, groupid: 2, location: "jubin", name: null, personid: 1, presense: 1367392633, response: null, text: null, time: 1367336766, type: 0} ]
and have this(short version):
[ { callid: 4, name: {"vahid", "reza"} }, { callid: 5, name: {"vahid", null} } ]
can 1 help,
tried every things , ifs i'm doing wrong in somewhere in forward
try using _
, http://jsfiddle.net/swdsm/3/
this convert data
array arr[callid] = [name, ...]
var arr = _.inject(data, function (memo, row) { memo[row.callid] || (memo[row.callid] = []); if (row.name != null && memo[row.callid].indexof(row.name) == -1) { memo[row.callid].push(row.name); } return memo; }, []);
and convert u expect
var result = []; (var key in arr) { result.push({callid: key, name: arr[key]}); }
Comments
Post a Comment