如何恢复2导致相同的功能

时间:2017-08-16 15:19:28

标签: javascript

我有一个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 + "]";
}

它会在result1result2中返回相同的值。 如何重新记录result2

的值 你能帮帮我吗? 谢谢。

1 个答案:

答案 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
}