一个集合返回 11 个项目,如下所示;
( 1, "Ball", "Result1")
( 2, "Ball", " Result2")
( 3, "Ball", " Result3")
( 4, "Ball", " Result4")
( 5, "Ball", " Result5")
( 6, "Ball", " Result6")
( 7, "Ball", " Result7")
( 8, "Ball", " Result8")
( 9, "Pool", " Pool 1")
( 10, "Pool", " Pool 2")
( 11, "Pool", " Pool 3")
我想存储它们,将它们分组为四个项目.. 让我的数组看起来像这样
var data = [];
data.push({
myclass: "First4",
schedule: [ {
id : '1',
gameType: 'Ball',
result: 'Result11'
}, {
id: '2',
gameType: 'Ball',
result: 'Result2'
},........... ]
});
//second group
data.push({
divClass : "second4",
items : [ {
id : '5'
gameType: 'Ball',
result: 'Result5'
}, {
id : ''
gameType: 'Ball',
result: 'Result6
} ]
});
我如何编写一个 for 循环,以便我可以动态实现相同的结果,而不是手动编写推送
for(var i = 0; i < collLength; i++){
// do push 1 with first four //data.push(class, sheculde first 4 items, result)
// do second push with second four
// do third push with the remaining
}