2017-12-21 14 views
-1

js에서 .ejs 템플릿 파일로 변수를 전달하려고합니다. 값은 페이지를 처음 열 때 나타나지만 새로 고침 페이지에는 나타나지 않습니다. 변수를 로그 할 때마다 새로 고침 할 때마다 콘솔에 표시됩니다.node.js 및 ejs 변수가 페이지 새로 고침시 표시되지 않음

EJS :

<input type="text" value="<%= userfb.testTarget %>" data-min="<%= userfb.testMin %>" data-max="<%= userfb.testMax %>" data-fgcolor="#157fa2" class="dial ringtarget"> 

는 app.js

var query = firebase.database().ref('/doctors/patients/' + request.id + "/testResults"); 
    query.once("value") 
     .then(function(snapshot) { 
     snapshot.forEach(function(childSnapshot) { 
      var resultData = childSnapshot.val(); 
      var testid= resultData.testid; 
      console.log("testid:"+testid); 

      //Setting Test Results 
      // Loop through users in order with the forEach() method. The callback 
      // provided to forEach() will be called synchronously with a DataSnapshot 
      // for each child: 
        var childData = childSnapshot.val(); 
        console.log(childData.testResultValues); 
        var testResultValues =[]; 
        for (i in childData.testResultValues) { 
        testResultValues.push(childData.testResultValues[i].value); 
        } 
        userfb.testResultValues=testResultValues; 
        console.log(testResultValues);   


      //Getting test informations  
      var testquery = firebase.database().ref('/doctors/tests').orderByChild("testID").equalTo(testid); 
      testquery.once("value") 
       .then(function(snapshot2) { 
        snapshot2.forEach(function(snapshot2) { 
         var testData = snapshot2.val(); 
         userfb.testName=testData.testName; 
         userfb.testMax=testData.limitValues.max; 
         userfb.testMin=testData.limitValues.min; 
         userfb.testTarget=testData.normalValues.Female; 
         console.log("testmax:"+userfb.testMax); 
        }); 
      }); 


     }); 

    }); 

답변

0

해결 방법 : I는 각 중포 기지 쿼리 (userfb 및 testInformations로) 반환 값을 나누어

지금은 새로 고침 페이지 작업 .

var query = firebase.database().ref('/doctors/patients/' + request.id + "/testResults"); 
query.once("value") 
    .then(function(snapshot) { 
    snapshot.forEach(function(childSnapshot) { 
     var resultData = childSnapshot.val(); 
     var testid= resultData.testid; 
     console.log("testid:"+testid); 

     //Setting Test Results 
     // Loop through users in order with the forEach() method. The callback 
     // provided to forEach() will be called synchronously with a DataSnapshot 
     // for each child: 
       var childData = childSnapshot.val(); 
       console.log(childData.testResultValues); 
       var testResultValues =[]; 
       for (i in childData.testResultValues) { 
       testResultValues.push(childData.testResultValues[i].value); 
       } 
       userfb.testResultValues=testResultValues; 
       console.log(testResultValues);   


     //Getting test informations  
     var testquery = firebase.database().ref('/doctors/tests').orderByChild("testID").equalTo(testid); 
     testquery.once("value") 
      .then(function(snapshot2) { 
      testInformations = snapshot2.val() 
       snapshot2.forEach(function(snapshot2) { 
        var testData = snapshot2.val(); 
        testInformations.testName=testData.testName; 
        testInformations.testMax=testData.limitValues.max; 
        testInformations.testMin=testData.limitValues.min; 
        testInformations.testTarget=testData.normalValues.Female; 
        console.log("testmax:"+testInformations.testMax); 
       }); 
     }); 


    }); 

});