我有一个未排序的数组,其中包含一些数据,我想创建一个新的数组,其中包含已排序的数据:
未排序的数据看起来像对象数组,我想将其分组。
等等…… 我尝试过使用array.map和reduce,但它们在IE中似乎不起作用, 同时我也尝试过:
"aggregation_content" 是什么。
新数据是从头开始的网格数据。 这对于第一次聚合非常完美。但问题在于,当我聚合新数据数组时,我需要使用...
"并且[o]应该是[n]节点的父节点。好的-第二组也可以使用那个代码,但是当我想要创建5个内部组时,我需要这样做:"
这怎么可以通过编程实现?如果我这样做:
我希望我写的文本能被理解 :D
____编辑于2012年12月13日______________________________________
输入数据如下:
输出数据应该是类似于这样的:
树状视图应该是两个或更多的嵌套节点。
var gridData = [], i = -1;
while (i++ < 5) {
gridData[i] = {
"ProjectOwner": ["Corporation1","Corporation2","Corporation3"][i % 2],
"ProjectId": i,
"ProjectName": String.fromCharCode("A".charCodeAt(0) + i % 3) + (1 + i % 3),
"ProjectType": ["Conference","Programming","Research","Conference"][i % 4],
"ProjectLeader": "Name1Name2Name3".substr(i % 3 * 5,5) + " " + "Surname1Surname2Surname3".substr(i % 3 * 8,8),
"StartDate": new Date(2009 + i % 4 % 2, (i + 3) % 12, 5 + i * 4 % 24).toLocaleDateString(),
"EndDate": new Date(2010 + i % 4 % 2, (i + 3) % 12, 5 + i * 4 % 24).toLocaleDateString(),
"Summary": "bla bla"
};
}
未排序的数据看起来像对象数组,我想将其分组。
//First group by ProjectOwner
Object {Corporation1: Array[3], Corporation2: Array[3]}
//Second group by ProjectName
Corporation1: Array[x]
A1 : Array [x]
Object1
Object2
...
Corporation2: Array[x]
等等…… 我尝试过使用array.map和reduce,但它们在IE中似乎不起作用, 同时我也尝试过:
$.each(aggregation_content, function(i,aggr) {
$.each(_newData, function(a, objA) {
if(i > 0)
o = _newData[a][aggregation_content[i - 1].cell];
n = _newData[a][aggregation_content[i].cell];
if(typeof o == "undefined") //For first row when new Data is empty array
{
if(! (n in newData))
newData[n] = [];
newData[n].push(objA);
}
})})
console.log(newData);
"aggregation_content" 是什么。
{cell:"ProjectOwner",value:""},{cell:"ProjectName",value:""},{cell:"ProjectLeader",value:""},{cell:"ProjectType",value:""}
新数据是从头开始的网格数据。 这对于第一次聚合非常完美。但问题在于,当我聚合新数据数组时,我需要使用...
if(! (n in newData[o]))
newData[o][n] = [];
newData[o][n].push(objA);
"并且[o]应该是[n]节点的父节点。好的-第二组也可以使用那个代码,但是当我想要创建5个内部组时,我需要这样做:"
newData["firstGroup"]["secondGroup"]["thirdGroup"]...[n].push("Some content").
这怎么可以通过编程实现?如果我这样做:
newData = newData[o] - no good
or
temp = newData
do something to temp
newData[o] = temp not good eather :'(
我希望我写的文本能被理解 :D
____编辑于2012年12月13日______________________________________
输入数据如下:
[Object, Object, Object, Object, Object, Object]
0: Object
EndDate: "Monday, April 05, 2010"
ProjectId: 0
ProjectLeader: "Name1 Surname1"
ProjectName: "A1"
ProjectOwner: "Corporation1"
ProjectType: "Conference"
StartDate: "Sunday, April 05, 2009"
Summary: "bla bla"
__proto__: Object
1: Object
EndDate: "Monday, May 09, 2011"
ProjectId: 1
ProjectLeader: "Name2 Surname2"
ProjectName: "B2"
ProjectOwner: "Corporation2"
ProjectType: "Programming"
StartDate: "Sunday, May 09, 2010"
Summary: "bla bla"
__proto__: Object
2: Object
...
3: Object
...
4: Object
...
5: Object
....
输出数据应该是类似于这样的:
Object {Corporation1: Array[3], Corporation2: Array[3]}
Corporation1: Array[2]
0: A1: Array[X]
0: Object
EndDate: "Monday, May 09, 2011"
ProjectId: 1
ProjectLeader: "Name2 Surname2"
ProjectName: "A1"
ProjectOwner: "Corporation2"
ProjectType: "Programming"
StartDate: "Sunday, May 09, 2010"
Summary: "bla bla"
1: Object
...
...
1: B2: Array[X]
0: Object
EndDate: "Monday, May 09, 2011"
ProjectId: 1
ProjectLeader: "Name2 Surname2"
ProjectName: "B2"
ProjectOwner: "Corporation2"
ProjectType: "Programming"
StartDate: "Sunday, May 09, 2010"
Summary: "bla bla"
1: Object
...
...
Corporation2: Array[2]
0: A1: Array[X]
0: Object
EndDate: "Monday, May 09, 2011"
ProjectId: 1
ProjectLeader: "Name2 Surname2"
ProjectName: "A1"
ProjectOwner: "Corporation2"
ProjectType: "Programming"
StartDate: "Sunday, May 09, 2010"
Summary: "bla bla"
1: Object
...
...
1: B2: Array[X]
0: Object
EndDate: "Monday, May 09, 2011"
ProjectId: 1
ProjectLeader: "Name2 Surname2"
ProjectName: "B2"
ProjectOwner: "Corporation2"
ProjectType: "Programming"
StartDate: "Sunday, May 09, 2010"
Summary: "bla bla"
1: Object
...
...
树状视图应该是两个或更多的嵌套节点。