2017-11-28 1 views
0

for 루프가 여러 개 있습니다. 그러나 내 마지막 for 루프가 예상대로 작동하지 않습니다. (match의 code_string)에 대해 그것은 내 일치 문자열의 각 코드를 통과해야합니다.반복이 제대로 작동하지 않습니다.

예를 들어, 내 출력해야한다 :

Initial Programming One-time Charge $9.1 

    Monthly Cost $2.65 

그러나 나는 모두 9.1을 얻고 보이지 않는 어떤 이유로

.

더 나은 이해를 위해 사진을 첨부했습니다. 당신이 당신의 로그에 정확한 예상 결과를 가지고 (I이 태클의보다 효율적인 방법이 될 수있다 생각하지만) enter image description here

for (var key in t.data.codes_prices_array) { 
 

 
     for (code in code_to_match) { 
 
\t \t \t \t 
 
\t \t \t // \t for (code_string in match){ 
 
\t \t \t \t \t  //if 251 == 251 
 
     if (code_to_match[code] == c.data.codes_prices_array[key].u_charge_code) { 
 
\t \t \t \t \t console.log("code to match", code_to_match[code], "u_charge_code", c.data.codes_prices_array[key].u_charge_code); 
 
\t \t \t \t \t \t for (code_string in match){ 
 
\t \t \t \t \t //if it is not blank or doesn't have a price of 0 (changed 2013-2-6) 
 
\t \t \t \t \t if (c.data.codes_prices_array[key].u_price!= '' && c.data.codes_prices_array[key] != 0){ 
 
\t \t \t \t \t \t strVal = strVal.replace(match[code_string], "$" + c.data.codes_prices_array[key].u_price); 
 
\t \t \t \t \t \t t.data.u_pricing = strVal; 
 
\t \t \t \t \t \t console.log("MONTHLY PRICE", match[code_string], "$" + c.data.codes_prices_array[key].u_price); 
 
\t \t \t \t \t } 
 
\t \t \t \t \t else{ 
 
\t \t \t \t \t \t strVal = strVal.replace(match[code_string], "$" + c.data.codes_prices_array[key].u_one_time_charge); 
 
\t \t \t \t \t \t t.data.u_pricing = strVal; 
 
\t \t \t \t \t \t console.log("ONE TIME ", match[code_string], "$" + c.data.codes_prices_array[key].u_one_time_charge); 
 
\t \t \t \t \t } 
 

 
     } 
 
\t \t \t \t } 
 
     } 
 

 
    }

답변

0

보고, 문제는 루프 자체 아니다 오히려 결과를 채우는 방식과 관련이 있습니다. 실제로 DOM을 채우는 데 사용되는 코드를 제공하면 문제가 무엇인지 정확하게 지적 할 수 있어야합니다.

관련 문제