2017-12-11 1 views
-1

배열에있는 행의 값을 이전 상주와 동일한 거주자 및 동일한 약물을 가지고있을 때 변경하려고합니다.Google 시트 스크립트에서 행을 변경하는 이유는 무엇입니까?

//check if something from one time per day 
    if (startTime[resMedVals[resMedRow][3]]){ 
     medPlan[lastRow].push(startTime[resMedVals[resMedRow][3]]+":00");     
    }else{ 
     medPlan[lastRow].push("More") 
    }//end if time 

그런 다음이 "추가"값으로 다시 및 거래 진행됩니다, 그래서 경우 기본값이 "추가"를 설정 -

는 처음에 그것이 작업을 반복되면 보인다. 처음 작업을 반복하는 경우 초기 시작 시간 값을 설정합니다. 반복하는 경우 필요한만큼의 행을 복사합니다.

//if more times per day medicine, then replicate tasks 
    if(medPlan[lastRow][9]== "More"){ 
     var timesToReplicate = medPlan[lastRow][5].charAt(0) 

     for(var i=0; i < timesToReplicate; i++){ 
     if (i==0){ 
      //first time 
      medPlan[lastRow][9] = workDay["start"] 
      medPlan[lastRow][9] += ":00" 

     }else{ 

      //add entire last entire row 
      medPlan.push(medPlan[medPlan.length-1]); 

     }//end if else first time 

이 부분까지 제대로 작동합니다.

그런 다음 반복되는 (그리고 처음이 아닌) 값에 대해 다른 값을 설정하려고합니다.

//adjust More values to appropriate starting times 
    for (var med=1; med < medPlan.length; med++){ 
    if(medPlan[med][2] == medPlan[med-1][2] && medPlan[med][1] == medPlan[med-1][1]){ 
     Logger.log(med) 
     var interval = Math.floor(workingHours/medPlan[med][5].charAt(0)); 

     medPlan[med][9] = interval 
    }//end if the same medication and the same resident 

    }//end for medPlan 

그러나 로그에서 오른쪽 행을 결정한다고 표시하더라도 반복 작업의 첫 번째 행을 계속 변경합니다.

Log output 현재 결과 : Current result

어떤 도움이 많이 감사합니다!

+0

시트에 실제로 값을 설정하는 코드를 게시 할 수 있습니까? –

답변

0

참조 문제였습니다. .slice (0)를 추가하여 문제를 해결해야했습니다.

medPlan.push(medPlan[medPlan.length-1].slice(0)); 
관련 문제