2017-03-03 63 views
0
Html Code: 

    <h3>Hello Welcome</h3> 

    <div>{{jsonData}}</div> 

Script Code: 

     function beforeRender(req, res, done) { 
     require('request')({ 
      url:'http://samples.openweathermap.org/data/2.5/weather?  lat=35&lon=139&appid=b1b15e88fa797225412429c1c50c122a1', 
      json:true, 
      method: 'GET' 
     }, function(err, response, body){ 
      console.log(JSON.stringify(body)); 
      req.data = { jsonData: body }; 
      done(); 
     }); 


    } 



The api is returns following Json Data: 
{ 
"coord": { 
    "lon": 139.01, 
    "lat": 35.02 
}, 
"weather": [ 
    { 
     "id": 800, 
     "main": "Clear", 
     "description": "clear sky", 
     "icon": "01n" 
    } 
], 
"base": "stations", 
"main": { 
    "temp": 285.514, 
    "pressure": 1013.75, 
    "humidity": 100, 
    "temp_min": 285.514, 
    "temp_max": 285.514, 
    "sea_level": 1023.22, 
    "grnd_level": 1013.75 
}, 
"wind": { 
    "speed": 5.52, 
    "deg": 311 
}, 
"clouds": { 
    "all": 0 
}, 
"dt": 1485792967, 
"sys": { 
    "message": 0.0025, 
    "country": "JP", 
    "sunrise": 1485726240, 
    "sunset": 1485763863 
}, 
"id": 1907296, 
"name": "Tawarano", 
"cod": 200 

}如何使用jsreport工作室

這是jsreport代碼顯示API數據。現在我試圖通過其餘的api獲取數據。我不知道如何在控制檯中打印api數據,我需要幫助來了解如何使用jsrender跟隨json數據並在控制檯中顯示。

回答

0

的出將來自於所有jsreport HTTP阿賈克斯下列對象在腳本部分

「jsreport.data」

在這個對象將有我們的所有數據。您只需在腳本中打印以下代碼

console.log(「data is are are:」,jsreport.data);