我有一个javascript函数:
var query1 = {{repair_semestre1}};
var query2 = {{repair_semestre2}};
var result1 = [];
var result2 = [];
for (var i = 0; i < query1.LRU.length; i++) {
result1.push(formatName(query1.LRU[i], query1.Client[i], query1.round[i]));
}
for (var i = 0; i < query2.LRU.length; i++) {
result2.push(formatName(query1.LRU[i], query1.Client[i], query1.round[i]));
}
return {
result1: result1,
result2: result2
};
function formatName(lru, turnover, round) {
return "[" + lru + "," + turnover + "," + round + "]";
}
它会在result1
和result2
中返回相同的值。
如何重新记录result2
。
答案 0 :(得分:4)
只是一个错字,在你的第二个for循环中,你从query1而不是query2
获取值for (var i = 0; i < query2.LRU.length; i++) {
result2.push(formatName(query1.LRU[i], query1.Client[i], query1.round[i]));//original
result2.push(formatName(query2.LRU[i], query2.Client[i], query2.round[i])); //change to this
}