Javascript 将数组的对象分组以进行敲除绑定
我有一个长度为27的对象数组:Javascript 将数组的对象分组以进行敲除绑定,javascript,knockout.js,Javascript,Knockout.js,我有一个长度为27的对象数组: [object(array)] .... .... 此数组中的每个项都是空的或由数组的对象组成,该数组的属性如下所示。这可能有几个循环,因此它将有许多对象 function MainTests(testName, section, totalExpected, totalPasssed, totalDuration, loopExpected, loopPassed, loopDuration) { var self = this;
[object(array)]
....
....
此数组中的每个项都是空的或由数组的对象组成,该数组的属性如下所示。这可能有几个循环,因此它将有许多对象
function MainTests(testName, section, totalExpected, totalPasssed, totalDuration, loopExpected, loopPassed, loopDuration) {
var self = this;
self.sectionName = section;
self.testName = testName;
self.totalPassExpect = totalExpected;
self.totalPassRate = totalPasssed;
self.totalDuration = totalDuration;
self.loopPassExpected = loopExpected;
self.loopPassRate = loopPassed;
self.loopDuration = loopDuration;
}
我想按sectionName
和testName
进行分组,如下所示:
{
section: sectionName,
tests: [testName:testName, totalPassExpect: totalExpected........loopDuration:loopDuration..]
}
我尝试了这个方法,但它只按sectionName
对其进行分组:
self.GroupMainTest = ko.computed(function () {
var mainTestArray = [];
for (var i = 0; i < allMainTests.length ; i++) {
var group = {};
var result = allMainTests[i];
if (result.length != 0) {
for (var j = 0; j < result.length; j++) {
if (group[result[j].sectionName] == undefined) {
group[result[j].sectionName] = [group[result[j].sectionName]];
}
group[result[j].sectionName].push(result[j].sectionName)
group[result[j].sectionName].push(result[j].totalPassExpect)
group[result[j].sectionName].push(result[j].totalPassRate)
group[result[j].sectionName].push(result[j].totalDuration)
group[result[j].sectionName].push(result[j].loopPassExpected)
group[result[j].sectionName].push(result[j].loopPassRate)
group[result[j].sectionName].push(result[j].loopDuration)
group[result[j].sectionName].push(result[j].testName)
}
mainTestArray.push(group);
}
else {
mainTestArray.push(result);
}
}
return mainTestArray;
});
self.GroupMainTest=ko.computed(函数(){
var mainTestArray=[];
对于(变量i=0;i
我的目标是实现类似的目标
您能帮忙吗?您可能需要校对您的问题。。很难读懂。。。但如果我理解正确的话,我建议在推之前不仅要检查sectionname,还要检查testName。。。。抱歉,您的代码有点混乱,您的问题更难理解:(您能不能只生成一个简单的图像,显示您期望的输出?请不要显示此代码,而是添加一个条目数组示例和期望的结果。您问题中的所有信息都是无关的。